commander 2.10.0 → 2.11.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 +17 -0
- package/Readme.md +1 -2
- package/index.js +33 -25
- package/package.json +4 -9
package/History.md
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
|
|
2
|
+
2.11.0 / 2017-07-03
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* Fix help section order and padding (#652)
|
|
6
|
+
* feature: support for signals to subcommands (#632)
|
|
7
|
+
* Fixed #37, --help should not display first (#447)
|
|
8
|
+
* Fix translation errors. (#570)
|
|
9
|
+
* Add package-lock.json
|
|
10
|
+
* Remove engines
|
|
11
|
+
* Upgrade package version
|
|
12
|
+
* Prefix events to prevent conflicts between commands and options (#494)
|
|
13
|
+
* Removing dependency on graceful-readlink
|
|
14
|
+
* Support setting name in #name function and make it chainable
|
|
15
|
+
* Add .vscode directory to .gitignore (Visual Studio Code metadata)
|
|
16
|
+
* Updated link to ruby commander in readme files
|
|
17
|
+
|
|
2
18
|
2.10.0 / 2017-06-19
|
|
3
19
|
==================
|
|
20
|
+
|
|
4
21
|
* Update .travis.yml. drop support for older node.js versions.
|
|
5
22
|
* Fix require arguments in README.md
|
|
6
23
|
* On SemVer you do not start from 0.0.1
|
package/Readme.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://www.npmjs.org/package/commander)
|
|
7
7
|
[](https://gitter.im/tj/commander.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
8
8
|
|
|
9
|
-
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/
|
|
9
|
+
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/commander-rb/commander).
|
|
10
10
|
[API documentation](http://tj.github.com/commander.js/)
|
|
11
11
|
|
|
12
12
|
|
|
@@ -349,4 +349,3 @@ More Demos can be found in the [examples](https://github.com/tj/commander.js/tre
|
|
|
349
349
|
## License
|
|
350
350
|
|
|
351
351
|
MIT
|
|
352
|
-
|
package/index.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
var EventEmitter = require('events').EventEmitter;
|
|
6
6
|
var spawn = require('child_process').spawn;
|
|
7
|
-
var readlink = require('graceful-readlink').readlinkSync;
|
|
8
7
|
var path = require('path');
|
|
9
8
|
var dirname = path.dirname;
|
|
10
9
|
var basename = path.basename;
|
|
@@ -302,8 +301,8 @@ Command.prototype.action = function(fn) {
|
|
|
302
301
|
};
|
|
303
302
|
var parent = this.parent || this;
|
|
304
303
|
var name = parent === this ? '*' : this._name;
|
|
305
|
-
parent.on(name, listener);
|
|
306
|
-
if (this._alias) parent.on(this._alias, listener);
|
|
304
|
+
parent.on('command:' + name, listener);
|
|
305
|
+
if (this._alias) parent.on('command:' + this._alias, listener);
|
|
307
306
|
return this;
|
|
308
307
|
};
|
|
309
308
|
|
|
@@ -390,7 +389,7 @@ Command.prototype.option = function(flags, description, fn, defaultValue) {
|
|
|
390
389
|
|
|
391
390
|
// when it's passed assign the value
|
|
392
391
|
// and conditionally invoke the callback
|
|
393
|
-
this.on(oname, function(val) {
|
|
392
|
+
this.on('option:' + oname, function(val) {
|
|
394
393
|
// coercion
|
|
395
394
|
if (null !== val && fn) val = fn(val, undefined === self[name]
|
|
396
395
|
? defaultValue
|
|
@@ -513,7 +512,7 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
|
|
513
512
|
// In case of globally installed, get the base dir where executable
|
|
514
513
|
// subcommand file should be located at
|
|
515
514
|
var baseDir
|
|
516
|
-
, link =
|
|
515
|
+
, link = fs.lstatSync(f).isSymbolicLink() ? fs.readlinkSync(f) : f;
|
|
517
516
|
|
|
518
517
|
// when symbolink is relative path
|
|
519
518
|
if (link !== f && link.charAt(0) !== '/') {
|
|
@@ -551,6 +550,14 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
|
|
551
550
|
proc = spawn(process.execPath, args, { stdio: 'inherit'});
|
|
552
551
|
}
|
|
553
552
|
|
|
553
|
+
var signals = ['SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGINT', 'SIGHUP'];
|
|
554
|
+
signals.forEach(function(signal) {
|
|
555
|
+
process.on(signal, function(){
|
|
556
|
+
if ((proc.killed === false) && (proc.exitCode === null)){
|
|
557
|
+
proc.kill(signal);
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
});
|
|
554
561
|
proc.on('close', process.exit.bind(process));
|
|
555
562
|
proc.on('error', function(err) {
|
|
556
563
|
if (err.code == "ENOENT") {
|
|
@@ -624,10 +631,10 @@ Command.prototype.parseArgs = function(args, unknown) {
|
|
|
624
631
|
|
|
625
632
|
if (args.length) {
|
|
626
633
|
name = args[0];
|
|
627
|
-
if (this.listeners(name).length) {
|
|
628
|
-
this.emit(args.shift(), args, unknown);
|
|
634
|
+
if (this.listeners('command:' + name).length) {
|
|
635
|
+
this.emit('command:' + args.shift(), args, unknown);
|
|
629
636
|
} else {
|
|
630
|
-
this.emit('
|
|
637
|
+
this.emit('command:*', args);
|
|
631
638
|
}
|
|
632
639
|
} else {
|
|
633
640
|
outputHelpIfNecessary(this, unknown);
|
|
@@ -700,7 +707,7 @@ Command.prototype.parseOptions = function(argv) {
|
|
|
700
707
|
if (option.required) {
|
|
701
708
|
arg = argv[++i];
|
|
702
709
|
if (null == arg) return this.optionMissingArgument(option);
|
|
703
|
-
this.emit(option.name(), arg);
|
|
710
|
+
this.emit('option:' + option.name(), arg);
|
|
704
711
|
// optional arg
|
|
705
712
|
} else if (option.optional) {
|
|
706
713
|
arg = argv[i+1];
|
|
@@ -709,10 +716,10 @@ Command.prototype.parseOptions = function(argv) {
|
|
|
709
716
|
} else {
|
|
710
717
|
++i;
|
|
711
718
|
}
|
|
712
|
-
this.emit(option.name(), arg);
|
|
719
|
+
this.emit('option:' + option.name(), arg);
|
|
713
720
|
// bool
|
|
714
721
|
} else {
|
|
715
|
-
this.emit(option.name());
|
|
722
|
+
this.emit('option:' + option.name());
|
|
716
723
|
}
|
|
717
724
|
continue;
|
|
718
725
|
}
|
|
@@ -833,7 +840,7 @@ Command.prototype.version = function(str, flags) {
|
|
|
833
840
|
this._version = str;
|
|
834
841
|
flags = flags || '-V, --version';
|
|
835
842
|
this.option(flags, 'output the version number');
|
|
836
|
-
this.on('version', function() {
|
|
843
|
+
this.on('option:version', function() {
|
|
837
844
|
process.stdout.write(str + '\n');
|
|
838
845
|
process.exit(0);
|
|
839
846
|
});
|
|
@@ -898,15 +905,17 @@ Command.prototype.usage = function(str) {
|
|
|
898
905
|
};
|
|
899
906
|
|
|
900
907
|
/**
|
|
901
|
-
* Get the name of the command
|
|
908
|
+
* Get or set the name of the command
|
|
902
909
|
*
|
|
903
|
-
* @param {String}
|
|
910
|
+
* @param {String} str
|
|
904
911
|
* @return {String|Command}
|
|
905
912
|
* @api public
|
|
906
913
|
*/
|
|
907
914
|
|
|
908
|
-
Command.prototype.name = function() {
|
|
909
|
-
return this._name;
|
|
915
|
+
Command.prototype.name = function(str) {
|
|
916
|
+
if (0 === arguments.length) return this._name;
|
|
917
|
+
this._name = str;
|
|
918
|
+
return this;
|
|
910
919
|
};
|
|
911
920
|
|
|
912
921
|
/**
|
|
@@ -932,12 +941,11 @@ Command.prototype.largestOptionLength = function() {
|
|
|
932
941
|
Command.prototype.optionHelp = function() {
|
|
933
942
|
var width = this.largestOptionLength();
|
|
934
943
|
|
|
935
|
-
//
|
|
936
|
-
return
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
.join('\n');
|
|
944
|
+
// Append the help information
|
|
945
|
+
return this.options.map(function(option) {
|
|
946
|
+
return pad(option.flags, width) + ' ' + option.description;
|
|
947
|
+
}).concat([pad('-h, --help', width) + ' ' + 'output usage information'])
|
|
948
|
+
.join('\n');
|
|
941
949
|
};
|
|
942
950
|
|
|
943
951
|
/**
|
|
@@ -1013,17 +1021,17 @@ Command.prototype.helpInformation = function() {
|
|
|
1013
1021
|
if (commandHelp) cmds = [commandHelp];
|
|
1014
1022
|
|
|
1015
1023
|
var options = [
|
|
1016
|
-
'
|
|
1024
|
+
''
|
|
1025
|
+
, ' Options:'
|
|
1017
1026
|
, ''
|
|
1018
1027
|
, '' + this.optionHelp().replace(/^/gm, ' ')
|
|
1019
1028
|
, ''
|
|
1020
|
-
, ''
|
|
1021
1029
|
];
|
|
1022
1030
|
|
|
1023
1031
|
return usage
|
|
1024
|
-
.concat(cmds)
|
|
1025
1032
|
.concat(desc)
|
|
1026
1033
|
.concat(options)
|
|
1034
|
+
.concat(cmds)
|
|
1027
1035
|
.join('\n');
|
|
1028
1036
|
};
|
|
1029
1037
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.0",
|
|
4
4
|
"description": "the complete solution for node.js command-line programs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"commander",
|
|
@@ -15,20 +15,15 @@
|
|
|
15
15
|
"url": "https://github.com/tj/commander.js.git"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"should": "
|
|
19
|
-
"sinon": "
|
|
18
|
+
"should": "^11.2.1",
|
|
19
|
+
"sinon": "^2.3.5"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"test": "make test"
|
|
23
23
|
},
|
|
24
24
|
"main": "index",
|
|
25
|
-
"engines": {
|
|
26
|
-
"node": ">= 0.6.x"
|
|
27
|
-
},
|
|
28
25
|
"files": [
|
|
29
26
|
"index.js"
|
|
30
27
|
],
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"graceful-readlink": ">= 1.0.0"
|
|
33
|
-
}
|
|
28
|
+
"dependencies": {}
|
|
34
29
|
}
|