commander 2.14.1 → 2.15.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 +6 -0
- package/Readme.md +1 -1
- package/index.js +98 -24
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/Readme.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
[](http://travis-ci.org/tj/commander.js)
|
|
5
5
|
[](https://www.npmjs.org/package/commander)
|
|
6
|
-
[](https://
|
|
6
|
+
[](https://npmcharts.com/compare/commander?minimal=true)
|
|
7
7
|
[](https://gitter.im/tj/commander.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
8
8
|
|
|
9
9
|
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/commander-rb/commander).
|
package/index.js
CHANGED
|
@@ -869,13 +869,15 @@ Command.prototype.version = function(str, flags) {
|
|
|
869
869
|
* Set the description to `str`.
|
|
870
870
|
*
|
|
871
871
|
* @param {String} str
|
|
872
|
+
* @param {Object} argsDescription
|
|
872
873
|
* @return {String|Command}
|
|
873
874
|
* @api public
|
|
874
875
|
*/
|
|
875
876
|
|
|
876
|
-
Command.prototype.description = function(str) {
|
|
877
|
+
Command.prototype.description = function(str, argsDescription) {
|
|
877
878
|
if (arguments.length === 0) return this._description;
|
|
878
879
|
this._description = str;
|
|
880
|
+
this._argsDescription = argsDescription;
|
|
879
881
|
return this;
|
|
880
882
|
};
|
|
881
883
|
|
|
@@ -938,6 +940,45 @@ Command.prototype.name = function(str) {
|
|
|
938
940
|
return this;
|
|
939
941
|
};
|
|
940
942
|
|
|
943
|
+
/**
|
|
944
|
+
* Return prepared commands.
|
|
945
|
+
*
|
|
946
|
+
* @return {Array}
|
|
947
|
+
* @api private
|
|
948
|
+
*/
|
|
949
|
+
|
|
950
|
+
Command.prototype.prepareCommands = function() {
|
|
951
|
+
return this.commands.filter(function(cmd) {
|
|
952
|
+
return !cmd._noHelp;
|
|
953
|
+
}).map(function(cmd) {
|
|
954
|
+
var args = cmd._args.map(function(arg) {
|
|
955
|
+
return humanReadableArgName(arg);
|
|
956
|
+
}).join(' ');
|
|
957
|
+
|
|
958
|
+
return [
|
|
959
|
+
cmd._name +
|
|
960
|
+
(cmd._alias ? '|' + cmd._alias : '') +
|
|
961
|
+
(cmd.options.length ? ' [options]' : '') +
|
|
962
|
+
(args ? ' ' + args : ''),
|
|
963
|
+
cmd._description
|
|
964
|
+
];
|
|
965
|
+
});
|
|
966
|
+
};
|
|
967
|
+
|
|
968
|
+
/**
|
|
969
|
+
* Return the largest command length.
|
|
970
|
+
*
|
|
971
|
+
* @return {Number}
|
|
972
|
+
* @api private
|
|
973
|
+
*/
|
|
974
|
+
|
|
975
|
+
Command.prototype.largestCommandLength = function() {
|
|
976
|
+
var commands = this.prepareCommands();
|
|
977
|
+
return commands.reduce(function(max, command) {
|
|
978
|
+
return Math.max(max, command[0].length);
|
|
979
|
+
}, 0);
|
|
980
|
+
};
|
|
981
|
+
|
|
941
982
|
/**
|
|
942
983
|
* Return the largest option length.
|
|
943
984
|
*
|
|
@@ -946,11 +987,52 @@ Command.prototype.name = function(str) {
|
|
|
946
987
|
*/
|
|
947
988
|
|
|
948
989
|
Command.prototype.largestOptionLength = function() {
|
|
949
|
-
|
|
990
|
+
var options = [].slice.call(this.options);
|
|
991
|
+
options.push({
|
|
992
|
+
flags: '-h, --help'
|
|
993
|
+
});
|
|
994
|
+
return options.reduce(function(max, option) {
|
|
950
995
|
return Math.max(max, option.flags.length);
|
|
951
996
|
}, 0);
|
|
952
997
|
};
|
|
953
998
|
|
|
999
|
+
/**
|
|
1000
|
+
* Return the largest arg length.
|
|
1001
|
+
*
|
|
1002
|
+
* @return {Number}
|
|
1003
|
+
* @api private
|
|
1004
|
+
*/
|
|
1005
|
+
|
|
1006
|
+
Command.prototype.largestArgLength = function() {
|
|
1007
|
+
return this._args.reduce(function(max, arg) {
|
|
1008
|
+
return Math.max(max, arg.name.length);
|
|
1009
|
+
}, 0);
|
|
1010
|
+
};
|
|
1011
|
+
|
|
1012
|
+
/**
|
|
1013
|
+
* Return the pad width.
|
|
1014
|
+
*
|
|
1015
|
+
* @return {Number}
|
|
1016
|
+
* @api private
|
|
1017
|
+
*/
|
|
1018
|
+
|
|
1019
|
+
Command.prototype.padWidth = function() {
|
|
1020
|
+
var width = this.largestOptionLength();
|
|
1021
|
+
if (this._argsDescription && this._args.length) {
|
|
1022
|
+
if (this.largestArgLength() > width) {
|
|
1023
|
+
width = this.largestArgLength();
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
if (this.commands && this.commands.length) {
|
|
1028
|
+
if (this.largestCommandLength() > width) {
|
|
1029
|
+
width = this.largestCommandLength();
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
return width;
|
|
1034
|
+
};
|
|
1035
|
+
|
|
954
1036
|
/**
|
|
955
1037
|
* Return help for options.
|
|
956
1038
|
*
|
|
@@ -959,7 +1041,7 @@ Command.prototype.largestOptionLength = function() {
|
|
|
959
1041
|
*/
|
|
960
1042
|
|
|
961
1043
|
Command.prototype.optionHelp = function() {
|
|
962
|
-
var width = this.
|
|
1044
|
+
var width = this.padWidth();
|
|
963
1045
|
|
|
964
1046
|
// Append the help information
|
|
965
1047
|
return this.options.map(function(option) {
|
|
@@ -979,28 +1061,10 @@ Command.prototype.optionHelp = function() {
|
|
|
979
1061
|
Command.prototype.commandHelp = function() {
|
|
980
1062
|
if (!this.commands.length) return '';
|
|
981
1063
|
|
|
982
|
-
var commands = this.
|
|
983
|
-
|
|
984
|
-
}).map(function(cmd) {
|
|
985
|
-
var args = cmd._args.map(function(arg) {
|
|
986
|
-
return humanReadableArgName(arg);
|
|
987
|
-
}).join(' ');
|
|
988
|
-
|
|
989
|
-
return [
|
|
990
|
-
cmd._name +
|
|
991
|
-
(cmd._alias ? '|' + cmd._alias : '') +
|
|
992
|
-
(cmd.options.length ? ' [options]' : '') +
|
|
993
|
-
(args ? ' ' + args : ''),
|
|
994
|
-
cmd._description
|
|
995
|
-
];
|
|
996
|
-
});
|
|
997
|
-
|
|
998
|
-
var width = commands.reduce(function(max, command) {
|
|
999
|
-
return Math.max(max, command[0].length);
|
|
1000
|
-
}, 0);
|
|
1064
|
+
var commands = this.prepareCommands();
|
|
1065
|
+
var width = this.padWidth();
|
|
1001
1066
|
|
|
1002
1067
|
return [
|
|
1003
|
-
'',
|
|
1004
1068
|
' Commands:',
|
|
1005
1069
|
'',
|
|
1006
1070
|
commands.map(function(cmd) {
|
|
@@ -1025,6 +1089,17 @@ Command.prototype.helpInformation = function() {
|
|
|
1025
1089
|
' ' + this._description,
|
|
1026
1090
|
''
|
|
1027
1091
|
];
|
|
1092
|
+
|
|
1093
|
+
var argsDescription = this._argsDescription;
|
|
1094
|
+
if (argsDescription && this._args.length) {
|
|
1095
|
+
var width = this.padWidth();
|
|
1096
|
+
desc.push(' Arguments:');
|
|
1097
|
+
desc.push('');
|
|
1098
|
+
this._args.forEach(function(arg) {
|
|
1099
|
+
desc.push(' ' + pad(arg.name, width) + ' ' + argsDescription[arg.name]);
|
|
1100
|
+
});
|
|
1101
|
+
desc.push('');
|
|
1102
|
+
}
|
|
1028
1103
|
}
|
|
1029
1104
|
|
|
1030
1105
|
var cmdName = this._name;
|
|
@@ -1042,7 +1117,6 @@ Command.prototype.helpInformation = function() {
|
|
|
1042
1117
|
if (commandHelp) cmds = [commandHelp];
|
|
1043
1118
|
|
|
1044
1119
|
var options = [
|
|
1045
|
-
'',
|
|
1046
1120
|
' Options:',
|
|
1047
1121
|
'',
|
|
1048
1122
|
'' + this.optionHelp().replace(/^/gm, ' '),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"description": "the complete solution for node.js command-line programs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"commander",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@types/node": "^7.0.
|
|
29
|
+
"@types/node": "^7.0.55",
|
|
30
30
|
"eslint": "^3.19.0",
|
|
31
31
|
"should": "^11.2.1",
|
|
32
32
|
"sinon": "^2.4.1",
|
|
33
33
|
"standard": "^10.0.3",
|
|
34
|
-
"typescript": "^2.7.
|
|
34
|
+
"typescript": "^2.7.2"
|
|
35
35
|
},
|
|
36
36
|
"typings": "typings/index.d.ts"
|
|
37
37
|
}
|