1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var grunt = require('../grunt');
|
11 |
|
12 |
|
13 | var path = require('path');
|
14 |
|
15 |
|
16 | var nopt = require('nopt');
|
17 |
|
18 |
|
19 | var cli = module.exports = function(options, done) {
|
20 |
|
21 | if (options) {
|
22 |
|
23 | Object.keys(options).forEach(function(key) {
|
24 | if (!(key in cli.options)) {
|
25 |
|
26 | cli.options[key] = options[key];
|
27 | } else if (cli.optlist[key].type === Array) {
|
28 |
|
29 |
|
30 | [].push.apply(cli.options[key], options[key]);
|
31 | }
|
32 | });
|
33 | }
|
34 |
|
35 |
|
36 | grunt.tasks(cli.tasks, cli.options, done);
|
37 | };
|
38 |
|
39 |
|
40 | var optlist = cli.optlist = {
|
41 | help: {
|
42 | short: 'h',
|
43 | info: 'Display this help text.',
|
44 | type: Boolean
|
45 | },
|
46 | base: {
|
47 | info: 'Specify an alternate base path. By default, all file paths are relative to the "grunt.js" gruntfile. (grunt.file.setBase) *',
|
48 | type: path
|
49 | },
|
50 | color: {
|
51 | info: 'Disable colored output.',
|
52 | type: Boolean,
|
53 | negate: true
|
54 | },
|
55 | config: {
|
56 | info: 'Specify an alternate "grunt.js" gruntfile.',
|
57 | type: path
|
58 | },
|
59 | debug: {
|
60 | short: 'd',
|
61 | info: 'Enable debugging mode for tasks that support it. For detailed error stack traces, specify --debug 9.',
|
62 | type: Number
|
63 | },
|
64 | force: {
|
65 | short: 'f',
|
66 | info: 'A way to force your way past warnings. Want a suggestion? Don\'t use this option, fix your code.',
|
67 | type: Boolean
|
68 | },
|
69 | tasks: {
|
70 | info: 'Additional directory paths to scan for task and "extra" files. (grunt.loadTasks) *',
|
71 | type: Array
|
72 | },
|
73 | npm: {
|
74 | info: 'Npm-installed grunt plugins to scan for task and "extra" files. (grunt.loadNpmTasks) *',
|
75 | type: Array
|
76 | },
|
77 | write: {
|
78 | info: 'Disable writing files (dry run).',
|
79 | type: Boolean,
|
80 | negate: true
|
81 | },
|
82 | verbose: {
|
83 | short: 'v',
|
84 | info: 'Verbose mode. A lot more information output.',
|
85 | type: Boolean
|
86 | },
|
87 | version: {
|
88 | info: 'Print the grunt version.',
|
89 | type: Boolean
|
90 | }
|
91 | };
|
92 |
|
93 |
|
94 | var aliases = {};
|
95 | var known = {};
|
96 |
|
97 | Object.keys(optlist).forEach(function(key) {
|
98 | var short = optlist[key].short;
|
99 | if (short) {
|
100 | aliases[short] = '--' + key;
|
101 | }
|
102 | known[key] = optlist[key].type;
|
103 | });
|
104 |
|
105 | var parsed = nopt(known, aliases, process.argv, 2);
|
106 | cli.tasks = parsed.argv.remain;
|
107 | cli.options = parsed;
|
108 | delete parsed.argv;
|
109 |
|
110 |
|
111 | Object.keys(optlist).forEach(function(key) {
|
112 | if (optlist[key].type === Array && !(key in cli.options)) {
|
113 | cli.options[key] = [];
|
114 | }
|
115 | });
|