commander 2.16.0 → 2.19.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/CHANGELOG.md +26 -0
- package/Readme.md +23 -31
- package/index.js +25 -29
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
|
|
2
|
+
2.19.0 / 2018-10-02
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* Removed newline after Options and Commands headers (#864)
|
|
6
|
+
* Bugfix - Error output (#862)
|
|
7
|
+
* Fix to change default value to string (#856)
|
|
8
|
+
|
|
9
|
+
2.18.0 / 2018-09-07
|
|
10
|
+
==================
|
|
11
|
+
|
|
12
|
+
* Standardize help output (#853)
|
|
13
|
+
* chmod 644 travis.yml (#851)
|
|
14
|
+
* add support for execute typescript subcommand via ts-node (#849)
|
|
15
|
+
|
|
16
|
+
2.17.1 / 2018-08-07
|
|
17
|
+
==================
|
|
18
|
+
|
|
19
|
+
* Fix bug in command emit (#844)
|
|
20
|
+
|
|
21
|
+
2.17.0 / 2018-08-03
|
|
22
|
+
==================
|
|
23
|
+
|
|
24
|
+
* fixed newline output after help information (#833)
|
|
25
|
+
* Fix to emit the action even without command (#778)
|
|
26
|
+
* npm update (#823)
|
|
27
|
+
|
|
2
28
|
2.16.0 / 2018-06-29
|
|
3
29
|
==================
|
|
4
30
|
|
package/Readme.md
CHANGED
|
@@ -45,7 +45,7 @@ console.log(' - %s cheese', program.cheese);
|
|
|
45
45
|
|
|
46
46
|
Short flags may be passed as a single arg, for example `-abc` is equivalent to `-a -b -c`. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc.
|
|
47
47
|
|
|
48
|
-
Note that multi-word options starting with `--no` prefix negate the boolean value of the following word. For example, `--no-sauce` sets the value of `program.sauce` to false.
|
|
48
|
+
Note that multi-word options starting with `--no` prefix negate the boolean value of the following word. For example, `--no-sauce` sets the value of `program.sauce` to false.
|
|
49
49
|
|
|
50
50
|
```js
|
|
51
51
|
#!/usr/bin/env node
|
|
@@ -153,7 +153,7 @@ program
|
|
|
153
153
|
.option('-s --size <size>', 'Pizza size', /^(large|medium|small)$/i, 'medium')
|
|
154
154
|
.option('-d --drink [drink]', 'Drink', /^(coke|pepsi|izze)$/i)
|
|
155
155
|
.parse(process.argv);
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
console.log(' size: %j', program.size);
|
|
158
158
|
console.log(' drink: %j', program.drink);
|
|
159
159
|
```
|
|
@@ -248,22 +248,19 @@ You can enable `--harmony` option in two ways:
|
|
|
248
248
|
The help information is auto-generated based on the information commander already knows about your program, so the following `--help` info is for free:
|
|
249
249
|
|
|
250
250
|
```
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
Usage: pizza [options]
|
|
254
|
-
|
|
255
|
-
An application for pizzas ordering
|
|
251
|
+
$ ./examples/pizza --help
|
|
252
|
+
Usage: pizza [options]
|
|
256
253
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
-h, --help output usage information
|
|
260
|
-
-V, --version output the version number
|
|
261
|
-
-p, --peppers Add peppers
|
|
262
|
-
-P, --pineapple Add pineapple
|
|
263
|
-
-b, --bbq Add bbq sauce
|
|
264
|
-
-c, --cheese <type> Add the specified type of cheese [marble]
|
|
265
|
-
-C, --no-cheese You do not want any cheese
|
|
254
|
+
An application for pizzas ordering
|
|
266
255
|
|
|
256
|
+
Options:
|
|
257
|
+
-h, --help output usage information
|
|
258
|
+
-V, --version output the version number
|
|
259
|
+
-p, --peppers Add peppers
|
|
260
|
+
-P, --pineapple Add pineapple
|
|
261
|
+
-b, --bbq Add bbq sauce
|
|
262
|
+
-c, --cheese <type> Add the specified type of cheese [marble]
|
|
263
|
+
-C, --no-cheese You do not want any cheese
|
|
267
264
|
```
|
|
268
265
|
|
|
269
266
|
## Custom help
|
|
@@ -271,7 +268,7 @@ You can enable `--harmony` option in two ways:
|
|
|
271
268
|
You can display arbitrary `-h, --help` information
|
|
272
269
|
by listening for "--help". Commander will automatically
|
|
273
270
|
exit once you are done so that the remainder of your program
|
|
274
|
-
does not execute causing undesired
|
|
271
|
+
does not execute causing undesired behaviors, for example
|
|
275
272
|
in the following executable "stuff" will not output when
|
|
276
273
|
`--help` is used.
|
|
277
274
|
|
|
@@ -294,11 +291,10 @@ program
|
|
|
294
291
|
// node's emit() is immediate
|
|
295
292
|
|
|
296
293
|
program.on('--help', function(){
|
|
297
|
-
console.log('
|
|
298
|
-
console.log('');
|
|
299
|
-
console.log('
|
|
300
|
-
console.log('
|
|
301
|
-
console.log('');
|
|
294
|
+
console.log('')
|
|
295
|
+
console.log('Examples:');
|
|
296
|
+
console.log(' $ custom-help --help');
|
|
297
|
+
console.log(' $ custom-help -h');
|
|
302
298
|
});
|
|
303
299
|
|
|
304
300
|
program.parse(process.argv);
|
|
@@ -309,11 +305,9 @@ console.log('stuff');
|
|
|
309
305
|
Yields the following help output when `node script-name.js -h` or `node script-name.js --help` are run:
|
|
310
306
|
|
|
311
307
|
```
|
|
312
|
-
|
|
313
308
|
Usage: custom-help [options]
|
|
314
309
|
|
|
315
310
|
Options:
|
|
316
|
-
|
|
317
311
|
-h, --help output usage information
|
|
318
312
|
-V, --version output the version number
|
|
319
313
|
-f, --foo enable some foo
|
|
@@ -321,10 +315,8 @@ Options:
|
|
|
321
315
|
-B, --baz enable some baz
|
|
322
316
|
|
|
323
317
|
Examples:
|
|
324
|
-
|
|
325
318
|
$ custom-help --help
|
|
326
319
|
$ custom-help -h
|
|
327
|
-
|
|
328
320
|
```
|
|
329
321
|
|
|
330
322
|
## .outputHelp(cb)
|
|
@@ -402,11 +394,11 @@ program
|
|
|
402
394
|
.action(function(cmd, options){
|
|
403
395
|
console.log('exec "%s" using %s mode', cmd, options.exec_mode);
|
|
404
396
|
}).on('--help', function() {
|
|
405
|
-
console.log('
|
|
406
|
-
console.log();
|
|
407
|
-
console.log('
|
|
408
|
-
console.log('
|
|
409
|
-
console.log();
|
|
397
|
+
console.log('');
|
|
398
|
+
console.log('Examples:');
|
|
399
|
+
console.log('');
|
|
400
|
+
console.log(' $ deploy exec sequential');
|
|
401
|
+
console.log(' $ deploy exec async');
|
|
410
402
|
});
|
|
411
403
|
|
|
412
404
|
program
|
package/index.js
CHANGED
|
@@ -523,7 +523,7 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
|
|
523
523
|
// executable
|
|
524
524
|
var f = argv[1];
|
|
525
525
|
// name of the subcommand, link `pm-install`
|
|
526
|
-
var bin = basename(f,
|
|
526
|
+
var bin = basename(f, path.extname(f)) + '-' + args[0];
|
|
527
527
|
|
|
528
528
|
// In case of globally installed, get the base dir where executable
|
|
529
529
|
// subcommand file should be located at
|
|
@@ -539,11 +539,14 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
|
|
539
539
|
// prefer local `./<bin>` to bin in the $PATH
|
|
540
540
|
var localBin = path.join(baseDir, bin);
|
|
541
541
|
|
|
542
|
-
// whether bin file is a js script with explicit `.js` extension
|
|
542
|
+
// whether bin file is a js script with explicit `.js` or `.ts` extension
|
|
543
543
|
var isExplicitJS = false;
|
|
544
544
|
if (exists(localBin + '.js')) {
|
|
545
545
|
bin = localBin + '.js';
|
|
546
546
|
isExplicitJS = true;
|
|
547
|
+
} else if (exists(localBin + '.ts')) {
|
|
548
|
+
bin = localBin + '.ts';
|
|
549
|
+
isExplicitJS = true;
|
|
547
550
|
} else if (exists(localBin)) {
|
|
548
551
|
bin = localBin;
|
|
549
552
|
}
|
|
@@ -577,9 +580,9 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
|
|
577
580
|
proc.on('close', process.exit.bind(process));
|
|
578
581
|
proc.on('error', function(err) {
|
|
579
582
|
if (err.code === 'ENOENT') {
|
|
580
|
-
console.error('
|
|
583
|
+
console.error('error: %s(1) does not exist, try --help', bin);
|
|
581
584
|
} else if (err.code === 'EACCES') {
|
|
582
|
-
console.error('
|
|
585
|
+
console.error('error: %s(1) not executable. try chmod or run with root', bin);
|
|
583
586
|
}
|
|
584
587
|
process.exit(1);
|
|
585
588
|
});
|
|
@@ -660,6 +663,10 @@ Command.prototype.parseArgs = function(args, unknown) {
|
|
|
660
663
|
if (unknown.length > 0) {
|
|
661
664
|
this.unknownOption(unknown[0]);
|
|
662
665
|
}
|
|
666
|
+
if (this.commands.length === 0 &&
|
|
667
|
+
this._args.filter(function(a) { return a.required }).length === 0) {
|
|
668
|
+
this.emit('command:*');
|
|
669
|
+
}
|
|
663
670
|
}
|
|
664
671
|
|
|
665
672
|
return this;
|
|
@@ -785,9 +792,7 @@ Command.prototype.opts = function() {
|
|
|
785
792
|
*/
|
|
786
793
|
|
|
787
794
|
Command.prototype.missingArgument = function(name) {
|
|
788
|
-
console.error();
|
|
789
|
-
console.error(" error: missing required argument `%s'", name);
|
|
790
|
-
console.error();
|
|
795
|
+
console.error("error: missing required argument `%s'", name);
|
|
791
796
|
process.exit(1);
|
|
792
797
|
};
|
|
793
798
|
|
|
@@ -800,13 +805,11 @@ Command.prototype.missingArgument = function(name) {
|
|
|
800
805
|
*/
|
|
801
806
|
|
|
802
807
|
Command.prototype.optionMissingArgument = function(option, flag) {
|
|
803
|
-
console.error();
|
|
804
808
|
if (flag) {
|
|
805
|
-
console.error("
|
|
809
|
+
console.error("error: option `%s' argument missing, got `%s'", option.flags, flag);
|
|
806
810
|
} else {
|
|
807
|
-
console.error("
|
|
811
|
+
console.error("error: option `%s' argument missing", option.flags);
|
|
808
812
|
}
|
|
809
|
-
console.error();
|
|
810
813
|
process.exit(1);
|
|
811
814
|
};
|
|
812
815
|
|
|
@@ -819,9 +822,7 @@ Command.prototype.optionMissingArgument = function(option, flag) {
|
|
|
819
822
|
|
|
820
823
|
Command.prototype.unknownOption = function(flag) {
|
|
821
824
|
if (this._allowUnknownOption) return;
|
|
822
|
-
console.error();
|
|
823
|
-
console.error(" error: unknown option `%s'", flag);
|
|
824
|
-
console.error();
|
|
825
|
+
console.error("error: unknown option `%s'", flag);
|
|
825
826
|
process.exit(1);
|
|
826
827
|
};
|
|
827
828
|
|
|
@@ -833,9 +834,7 @@ Command.prototype.unknownOption = function(flag) {
|
|
|
833
834
|
*/
|
|
834
835
|
|
|
835
836
|
Command.prototype.variadicArgNotLast = function(name) {
|
|
836
|
-
console.error();
|
|
837
|
-
console.error(" error: variadic arguments must be last `%s'", name);
|
|
838
|
-
console.error();
|
|
837
|
+
console.error("error: variadic arguments must be last `%s'", name);
|
|
839
838
|
process.exit(1);
|
|
840
839
|
};
|
|
841
840
|
|
|
@@ -1046,7 +1045,7 @@ Command.prototype.optionHelp = function() {
|
|
|
1046
1045
|
// Append the help information
|
|
1047
1046
|
return this.options.map(function(option) {
|
|
1048
1047
|
return pad(option.flags, width) + ' ' + option.description +
|
|
1049
|
-
((option.bool && option.defaultValue !== undefined) ? ' (default: ' + option.defaultValue + ')' : '');
|
|
1048
|
+
((option.bool && option.defaultValue !== undefined) ? ' (default: ' + JSON.stringify(option.defaultValue) + ')' : '');
|
|
1050
1049
|
}).concat([pad('-h, --help', width) + ' ' + 'output usage information'])
|
|
1051
1050
|
.join('\n');
|
|
1052
1051
|
};
|
|
@@ -1065,12 +1064,11 @@ Command.prototype.commandHelp = function() {
|
|
|
1065
1064
|
var width = this.padWidth();
|
|
1066
1065
|
|
|
1067
1066
|
return [
|
|
1068
|
-
'
|
|
1069
|
-
'',
|
|
1067
|
+
'Commands:',
|
|
1070
1068
|
commands.map(function(cmd) {
|
|
1071
1069
|
var desc = cmd[1] ? ' ' + cmd[1] : '';
|
|
1072
1070
|
return (desc ? pad(cmd[0], width) : cmd[0]) + desc;
|
|
1073
|
-
}).join('\n').replace(/^/gm, '
|
|
1071
|
+
}).join('\n').replace(/^/gm, ' '),
|
|
1074
1072
|
''
|
|
1075
1073
|
].join('\n');
|
|
1076
1074
|
};
|
|
@@ -1086,17 +1084,17 @@ Command.prototype.helpInformation = function() {
|
|
|
1086
1084
|
var desc = [];
|
|
1087
1085
|
if (this._description) {
|
|
1088
1086
|
desc = [
|
|
1089
|
-
|
|
1087
|
+
this._description,
|
|
1090
1088
|
''
|
|
1091
1089
|
];
|
|
1092
1090
|
|
|
1093
1091
|
var argsDescription = this._argsDescription;
|
|
1094
1092
|
if (argsDescription && this._args.length) {
|
|
1095
1093
|
var width = this.padWidth();
|
|
1096
|
-
desc.push('
|
|
1094
|
+
desc.push('Arguments:');
|
|
1097
1095
|
desc.push('');
|
|
1098
1096
|
this._args.forEach(function(arg) {
|
|
1099
|
-
desc.push('
|
|
1097
|
+
desc.push(' ' + pad(arg.name, width) + ' ' + argsDescription[arg.name]);
|
|
1100
1098
|
});
|
|
1101
1099
|
desc.push('');
|
|
1102
1100
|
}
|
|
@@ -1107,8 +1105,7 @@ Command.prototype.helpInformation = function() {
|
|
|
1107
1105
|
cmdName = cmdName + '|' + this._alias;
|
|
1108
1106
|
}
|
|
1109
1107
|
var usage = [
|
|
1110
|
-
'',
|
|
1111
|
-
' Usage: ' + cmdName + ' ' + this.usage(),
|
|
1108
|
+
'Usage: ' + cmdName + ' ' + this.usage(),
|
|
1112
1109
|
''
|
|
1113
1110
|
];
|
|
1114
1111
|
|
|
@@ -1117,9 +1114,8 @@ Command.prototype.helpInformation = function() {
|
|
|
1117
1114
|
if (commandHelp) cmds = [commandHelp];
|
|
1118
1115
|
|
|
1119
1116
|
var options = [
|
|
1120
|
-
'
|
|
1121
|
-
'',
|
|
1122
|
-
'' + this.optionHelp().replace(/^/gm, ' '),
|
|
1117
|
+
'Options:',
|
|
1118
|
+
'' + this.optionHelp().replace(/^/gm, ' '),
|
|
1123
1119
|
''
|
|
1124
1120
|
];
|
|
1125
1121
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.19.0",
|
|
4
4
|
"description": "the complete solution for node.js command-line programs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"commander",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"lint": "eslint index.js",
|
|
19
19
|
"test": "node test/run.js && npm run test-typings",
|
|
20
|
-
"test-typings": "
|
|
20
|
+
"test-typings": "tsc -p tsconfig.json"
|
|
21
21
|
},
|
|
22
22
|
"main": "index",
|
|
23
23
|
"files": [
|
|
@@ -26,11 +26,12 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^
|
|
30
|
-
"eslint": "^
|
|
31
|
-
"should": "^
|
|
32
|
-
"sinon": "^
|
|
33
|
-
"standard": "^
|
|
29
|
+
"@types/node": "^10.11.3",
|
|
30
|
+
"eslint": "^5.6.1",
|
|
31
|
+
"should": "^13.2.3",
|
|
32
|
+
"sinon": "^6.3.4",
|
|
33
|
+
"standard": "^12.0.1",
|
|
34
|
+
"ts-node": "^7.0.1",
|
|
34
35
|
"typescript": "^2.9.2"
|
|
35
36
|
},
|
|
36
37
|
"typings": "typings/index.d.ts"
|