5 * Copyright (c) 2012 "Cowboy" Ben Alman
6 * Licensed under the MIT license.
7 * https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
10 var grunt = require('../grunt');
13 var path = require('path');
16 var nopt = require('nopt');
18 // This is only executed when run via command line.
19 var cli = module.exports = function(options, done) {
20 // CLI-parsed options override any passed-in "default" options.
22 // For each defult option...
23 Object.keys(options).forEach(function(key) {
24 if (!(key in cli.options)) {
25 // If this option doesn't exist in the parsed cli.options, add it in.
26 cli.options[key] = options[key];
27 } else if (cli.optlist[key].type === Array) {
28 // If this option's type is Array, append it to any existing array
29 // (or create a new array).
30 [].push.apply(cli.options[key], options[key]);
36 grunt.tasks(cli.tasks, cli.options, done);
40 var optlist = cli.optlist = {
43 info: 'Display this help text.',
47 info: 'Specify an alternate base path. By default, all file paths are relative to the "grunt.js" gruntfile. (grunt.file.setBase) *',
51 info: 'Disable colored output.',
56 info: 'Specify an alternate "grunt.js" gruntfile.',
61 info: 'Enable debugging mode for tasks that support it. For detailed error stack traces, specify --debug 9.',
66 info: 'A way to force your way past warnings. Want a suggestion? Don\'t use this option, fix your code.',
70 info: 'Additional directory paths to scan for task and "extra" files. (grunt.loadTasks) *',
74 info: 'Npm-installed grunt plugins to scan for task and "extra" files. (grunt.loadNpmTasks) *',
78 info: 'Disable writing files (dry run).',
84 info: 'Verbose mode. A lot more information output.',
88 info: 'Print the grunt version.',
93 // Parse `optlist` into a form that nopt can handle.
97 Object.keys(optlist).forEach(function(key) {
98 var short = optlist[key].short;
100 aliases[short] = '--' + key;
102 known[key] = optlist[key].type;
105 var parsed = nopt(known, aliases, process.argv, 2);
106 cli.tasks = parsed.argv.remain;
107 cli.options = parsed;
110 // Initialize any Array options that weren't initialized.
111 Object.keys(optlist).forEach(function(key) {
112 if (optlist[key].type === Array && !(key in cli.options)) {
113 cli.options[key] = [];