5
* Copyright (c) 2014 "Cowboy" Ben Alman
6
* Licensed under the MIT license.
7
* https://github.com/gruntjs/grunt/blob/master/LICENSE-MIT
12
var grunt = require('../grunt');
15
var path = require('path');
18
var nopt = require('nopt');
20
// This is only executed when run via command line.
21
var cli = module.exports = function(options, done) {
22
// CLI-parsed options override any passed-in "default" options.
24
// For each default option...
25
Object.keys(options).forEach(function(key) {
26
if (!(key in cli.options)) {
27
// If this option doesn't exist in the parsed cli.options, add it in.
28
cli.options[key] = options[key];
29
} else if (cli.optlist[key].type === Array) {
30
// If this option's type is Array, append it to any existing array
31
// (or create a new array).
32
[].push.apply(cli.options[key], options[key]);
38
grunt.tasks(cli.tasks, cli.options, done);
42
var optlist = cli.optlist = {
45
info: 'Display this help text.',
49
info: 'Specify an alternate base path. By default, all file paths are relative to the Gruntfile. (grunt.file.setBase) *',
53
info: 'Disable colored output.',
58
info: 'Specify an alternate Gruntfile. By default, grunt looks in the current or parent directories for the nearest Gruntfile.js or Gruntfile.coffee file.',
63
info: 'Enable debugging mode for tasks that support it.',
64
type: [Number, Boolean]
67
info: 'Print a stack trace when exiting with a warning or fatal error.',
72
info: 'A way to force your way past warnings. Want a suggestion? Don\'t use this option, fix your code.',
76
info: 'Additional directory paths to scan for task and "extra" files. (grunt.loadTasks) *',
80
info: 'Npm-installed grunt plugins to scan for task and "extra" files. (grunt.loadNpmTasks) *',
84
info: 'Disable writing files (dry run).',
90
info: 'Verbose mode. A lot more information output.',
95
info: 'Print the grunt version. Combine with --verbose for more info.',
98
// Even though shell auto-completion is now handled by grunt-cli, leave this
99
// option here for display in the --help screen.
101
info: 'Output shell auto-completion rules. See the grunt-cli documentation for more information.',
106
// Parse `optlist` into a form that nopt can handle.
110
Object.keys(optlist).forEach(function(key) {
111
var short = optlist[key].short;
113
aliases[short] = '--' + key;
115
known[key] = optlist[key].type;
118
var parsed = nopt(known, aliases, process.argv, 2);
119
cli.tasks = parsed.argv.remain;
120
cli.options = parsed;
123
// Initialize any Array options that weren't initialized.
124
Object.keys(optlist).forEach(function(key) {
125
if (optlist[key].type === Array && !(key in cli.options)) {
126
cli.options[key] = [];