5 process.title = 'grunt';
7 // Especially badass external libs.
8 var findup = require('findup-sync');
9 var resolve = require('resolve').sync;
12 var options = require('../lib/cli').options;
13 var completion = require('../lib/completion');
14 var info = require('../lib/info');
15 var path = require('path');
17 var basedir = process.cwd();
20 // Do stuff based on CLI options.
21 if ('completion' in options) {
22 completion.print(options.completion);
23 } else if (options.version) {
25 } else if (options.gruntfile) { //Note: if both `gruntfile` and `base` are set, use `gruntfile`
26 basedir = path.resolve(path.dirname(options.gruntfile));
27 } else if (options.base) {
28 basedir = path.resolve(options.base);
32 gruntpath = resolve('grunt', {basedir: basedir});
34 gruntpath = findup('lib/grunt.js');
35 // No grunt install found!
37 if (options.version) { process.exit(); }
38 if (options.help) { info.help(); }
39 info.fatal('Unable to find local grunt.', 99);
43 // Everything looks good. Require local grunt and run it.
44 require(gruntpath).cli();