commander 2.8.1 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/History.md +7 -2
- package/Readme.md +13 -4
- package/index.js +29 -22
- package/package.json +2 -2
package/History.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
|
|
2
|
-
2.
|
|
2
|
+
2.9.0 / 2015-10-13
|
|
3
3
|
==================
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
* Add option `isDefault` to set default subcommand #415 @Qix-
|
|
6
|
+
* Add callback to allow filtering or post-processing of help text #434 @djulien
|
|
7
|
+
* Fix `undefined` text in help information close #414 #416 @zhiyelee
|
|
6
8
|
|
|
9
|
+
2.8.1 / 2015-04-22
|
|
10
|
+
==================
|
|
7
11
|
|
|
12
|
+
* Back out `support multiline description` Close #396 #397
|
|
8
13
|
|
|
9
14
|
2.8.0 / 2015-04-07
|
|
10
15
|
==================
|
package/Readme.md
CHANGED
|
@@ -167,13 +167,15 @@ program
|
|
|
167
167
|
.version('0.0.1')
|
|
168
168
|
.command('install [name]', 'install one or more packages')
|
|
169
169
|
.command('search [query]', 'search with optional query')
|
|
170
|
-
.command('list', 'list packages installed')
|
|
170
|
+
.command('list', 'list packages installed', {isDefault: true})
|
|
171
171
|
.parse(process.argv);
|
|
172
172
|
```
|
|
173
173
|
|
|
174
174
|
When `.command()` is invoked with a description argument, no `.action(callback)` should be called to handle sub-commands, otherwise there will be an error. This tells commander that you're going to use separate executables for sub-commands, much like `git(1)` and other popular tools.
|
|
175
175
|
The commander will try to search the executables in the directory of the entry script (like `./examples/pm`) with the name `program-command`, like `pm-install`, `pm-search`.
|
|
176
176
|
|
|
177
|
+
Options can be passed with the call to `.command()`. Specifying `true` for `opts.noHelp` will remove the option from the generated help output. Specifying `true` for `opts.isDefault` will run the subcommand if no other subcommand is specified.
|
|
178
|
+
|
|
177
179
|
If the program is designed to be installed globally, make sure the executables have proper modes, like `755`.
|
|
178
180
|
|
|
179
181
|
### `--harmony`
|
|
@@ -266,14 +268,16 @@ Examples:
|
|
|
266
268
|
|
|
267
269
|
```
|
|
268
270
|
|
|
269
|
-
## .outputHelp()
|
|
271
|
+
## .outputHelp(cb)
|
|
270
272
|
|
|
271
273
|
Output help information without exiting.
|
|
274
|
+
Optional callback cb allows post-processing of help text before it is displayed.
|
|
272
275
|
|
|
273
276
|
If you want to display help by default (e.g. if no command was provided), you can use something like:
|
|
274
277
|
|
|
275
278
|
```js
|
|
276
279
|
var program = require('commander');
|
|
280
|
+
var colors = require('colors');
|
|
277
281
|
|
|
278
282
|
program
|
|
279
283
|
.version('0.0.1')
|
|
@@ -281,13 +285,18 @@ program
|
|
|
281
285
|
.parse(process.argv);
|
|
282
286
|
|
|
283
287
|
if (!process.argv.slice(2).length) {
|
|
284
|
-
program.outputHelp();
|
|
288
|
+
program.outputHelp(make_red);
|
|
285
289
|
}
|
|
290
|
+
|
|
291
|
+
function make_red(txt) {
|
|
292
|
+
return colors.red(txt); //display the help text in red on the console
|
|
293
|
+
}
|
|
286
294
|
```
|
|
287
295
|
|
|
288
|
-
## .help()
|
|
296
|
+
## .help(cb)
|
|
289
297
|
|
|
290
298
|
Output help information and exit immediately.
|
|
299
|
+
Optional callback cb allows post-processing of help text before it is displayed.
|
|
291
300
|
|
|
292
301
|
## Examples
|
|
293
302
|
|
package/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* Module dependencies.
|
|
4
3
|
*/
|
|
@@ -83,10 +82,10 @@ Option.prototype.is = function(arg) {
|
|
|
83
82
|
function Command(name) {
|
|
84
83
|
this.commands = [];
|
|
85
84
|
this.options = [];
|
|
86
|
-
this._execs =
|
|
85
|
+
this._execs = {};
|
|
87
86
|
this._allowUnknownOption = false;
|
|
88
87
|
this._args = [];
|
|
89
|
-
this._name = name;
|
|
88
|
+
this._name = name || '';
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
/**
|
|
@@ -165,6 +164,7 @@ Command.prototype.command = function(name, desc, opts) {
|
|
|
165
164
|
cmd.description(desc);
|
|
166
165
|
this.executables = true;
|
|
167
166
|
this._execs[cmd._name] = true;
|
|
167
|
+
if (opts.isDefault) this.defaultExecutable = cmd._name;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
cmd._noHelp = !!opts.noHelp;
|
|
@@ -184,7 +184,7 @@ Command.prototype.command = function(name, desc, opts) {
|
|
|
184
184
|
|
|
185
185
|
Command.prototype.arguments = function (desc) {
|
|
186
186
|
return this.parseExpectedArgs(desc.split(/ +/));
|
|
187
|
-
}
|
|
187
|
+
};
|
|
188
188
|
|
|
189
189
|
/**
|
|
190
190
|
* Add an implicit `help [cmd]` subcommand
|
|
@@ -446,7 +446,7 @@ Command.prototype.parse = function(argv) {
|
|
|
446
446
|
this._name = this._name || basename(argv[1], '.js');
|
|
447
447
|
|
|
448
448
|
// github-style sub-commands with no sub-command
|
|
449
|
-
if (this.executables && argv.length < 3) {
|
|
449
|
+
if (this.executables && argv.length < 3 && !this.defaultExecutable) {
|
|
450
450
|
// this user needs help
|
|
451
451
|
argv.push('--help');
|
|
452
452
|
}
|
|
@@ -461,6 +461,10 @@ Command.prototype.parse = function(argv) {
|
|
|
461
461
|
var name = result.args[0];
|
|
462
462
|
if (this._execs[name] && typeof this._execs[name] != "function") {
|
|
463
463
|
return this.executeSubCommand(argv, args, parsed.unknown);
|
|
464
|
+
} else if (this.defaultExecutable) {
|
|
465
|
+
// use the default subcommand
|
|
466
|
+
args.unshift(name = this.defaultExecutable);
|
|
467
|
+
return this.executeSubCommand(argv, args, parsed.unknown);
|
|
464
468
|
}
|
|
465
469
|
|
|
466
470
|
return result;
|
|
@@ -544,6 +548,7 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
|
|
544
548
|
process.exit(1);
|
|
545
549
|
});
|
|
546
550
|
|
|
551
|
+
// Store the reference to the child process
|
|
547
552
|
this.runningCommand = proc;
|
|
548
553
|
};
|
|
549
554
|
|
|
@@ -831,7 +836,7 @@ Command.prototype.version = function(str, flags) {
|
|
|
831
836
|
*/
|
|
832
837
|
|
|
833
838
|
Command.prototype.description = function(str) {
|
|
834
|
-
if (0
|
|
839
|
+
if (0 === arguments.length) return this._description;
|
|
835
840
|
this._description = str;
|
|
836
841
|
return this;
|
|
837
842
|
};
|
|
@@ -910,10 +915,10 @@ Command.prototype.optionHelp = function() {
|
|
|
910
915
|
|
|
911
916
|
// Prepend the help information
|
|
912
917
|
return [pad('-h, --help', width) + ' ' + 'output usage information']
|
|
913
|
-
|
|
914
|
-
|
|
918
|
+
.concat(this.options.map(function(option) {
|
|
919
|
+
return pad(option.flags, width) + ' ' + option.description;
|
|
915
920
|
}))
|
|
916
|
-
|
|
921
|
+
.join('\n');
|
|
917
922
|
};
|
|
918
923
|
|
|
919
924
|
/**
|
|
@@ -935,14 +940,10 @@ Command.prototype.commandHelp = function() {
|
|
|
935
940
|
|
|
936
941
|
return [
|
|
937
942
|
cmd._name
|
|
938
|
-
+ (cmd._alias
|
|
939
|
-
|
|
940
|
-
: '')
|
|
941
|
-
+ (cmd.options.length
|
|
942
|
-
? ' [options]'
|
|
943
|
-
: '')
|
|
943
|
+
+ (cmd._alias ? '|' + cmd._alias : '')
|
|
944
|
+
+ (cmd.options.length ? ' [options]' : '')
|
|
944
945
|
+ ' ' + args
|
|
945
|
-
|
|
946
|
+
, cmd.description()
|
|
946
947
|
];
|
|
947
948
|
});
|
|
948
949
|
|
|
@@ -951,11 +952,12 @@ Command.prototype.commandHelp = function() {
|
|
|
951
952
|
}, 0);
|
|
952
953
|
|
|
953
954
|
return [
|
|
954
|
-
|
|
955
|
+
''
|
|
955
956
|
, ' Commands:'
|
|
956
957
|
, ''
|
|
957
958
|
, commands.map(function(cmd) {
|
|
958
|
-
|
|
959
|
+
var desc = cmd[1] ? ' ' + cmd[1] : '';
|
|
960
|
+
return pad(cmd[0], width) + desc;
|
|
959
961
|
}).join('\n').replace(/^/gm, ' ')
|
|
960
962
|
, ''
|
|
961
963
|
].join('\n');
|
|
@@ -1012,8 +1014,13 @@ Command.prototype.helpInformation = function() {
|
|
|
1012
1014
|
* @api public
|
|
1013
1015
|
*/
|
|
1014
1016
|
|
|
1015
|
-
Command.prototype.outputHelp = function() {
|
|
1016
|
-
|
|
1017
|
+
Command.prototype.outputHelp = function(cb) {
|
|
1018
|
+
if (!cb) {
|
|
1019
|
+
cb = function(passthru) {
|
|
1020
|
+
return passthru;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
process.stdout.write(cb(this.helpInformation()));
|
|
1017
1024
|
this.emit('--help');
|
|
1018
1025
|
};
|
|
1019
1026
|
|
|
@@ -1023,8 +1030,8 @@ Command.prototype.outputHelp = function() {
|
|
|
1023
1030
|
* @api public
|
|
1024
1031
|
*/
|
|
1025
1032
|
|
|
1026
|
-
Command.prototype.help = function() {
|
|
1027
|
-
this.outputHelp();
|
|
1033
|
+
Command.prototype.help = function(cb) {
|
|
1034
|
+
this.outputHelp(cb);
|
|
1028
1035
|
process.exit();
|
|
1029
1036
|
};
|
|
1030
1037
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"description": "the complete solution for node.js command-line programs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"command",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"should": ">= 0.0.1",
|
|
18
|
-
"sinon": ">=
|
|
18
|
+
"sinon": ">=1.17.1"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "make test"
|