commander 1.1.0 → 1.1.1
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 +6 -0
- package/index.js +11 -10
- package/package.json +1 -1
package/History.md
CHANGED
package/index.js
CHANGED
|
@@ -91,7 +91,7 @@ Option.prototype.is = function(arg){
|
|
|
91
91
|
function Command(name) {
|
|
92
92
|
this.commands = [];
|
|
93
93
|
this.options = [];
|
|
94
|
-
this.
|
|
94
|
+
this._args = [];
|
|
95
95
|
this._name = name;
|
|
96
96
|
}
|
|
97
97
|
|
|
@@ -189,10 +189,10 @@ Command.prototype.parseExpectedArgs = function(args){
|
|
|
189
189
|
args.forEach(function(arg){
|
|
190
190
|
switch (arg[0]) {
|
|
191
191
|
case '<':
|
|
192
|
-
self.
|
|
192
|
+
self._args.push({ required: true, name: arg.slice(1, -1) });
|
|
193
193
|
break;
|
|
194
194
|
case '[':
|
|
195
|
-
self.
|
|
195
|
+
self._args.push({ required: false, name: arg.slice(1, -1) });
|
|
196
196
|
break;
|
|
197
197
|
}
|
|
198
198
|
});
|
|
@@ -236,7 +236,7 @@ Command.prototype.action = function(fn){
|
|
|
236
236
|
// Leftover arguments need to be pushed back. Fixes issue #56
|
|
237
237
|
if (parsed.args.length) args = parsed.args.concat(args);
|
|
238
238
|
|
|
239
|
-
self.
|
|
239
|
+
self._args.forEach(function(arg, i){
|
|
240
240
|
if (arg.required && null == args[i]) {
|
|
241
241
|
self.missingArgument(arg.name);
|
|
242
242
|
}
|
|
@@ -245,8 +245,8 @@ Command.prototype.action = function(fn){
|
|
|
245
245
|
// Always append ourselves to the end of the arguments,
|
|
246
246
|
// to make sure we match the number of arguments the user
|
|
247
247
|
// expects
|
|
248
|
-
if (self.
|
|
249
|
-
args[self.
|
|
248
|
+
if (self._args.length) {
|
|
249
|
+
args[self._args.length] = self;
|
|
250
250
|
} else {
|
|
251
251
|
args.push(self);
|
|
252
252
|
}
|
|
@@ -676,7 +676,7 @@ Command.prototype.description = function(str){
|
|
|
676
676
|
*/
|
|
677
677
|
|
|
678
678
|
Command.prototype.usage = function(str){
|
|
679
|
-
var args = this.
|
|
679
|
+
var args = this._args.map(function(arg){
|
|
680
680
|
return arg.required
|
|
681
681
|
? '<' + arg.name + '>'
|
|
682
682
|
: '[' + arg.name + ']';
|
|
@@ -685,7 +685,8 @@ Command.prototype.usage = function(str){
|
|
|
685
685
|
var usage = '[options'
|
|
686
686
|
+ (this.commands.length ? '] [command' : '')
|
|
687
687
|
+ ']'
|
|
688
|
-
+ (this.
|
|
688
|
+
+ (this._args.length ? ' ' + args : '');
|
|
689
|
+
|
|
689
690
|
if (0 == arguments.length) return this._usage || usage;
|
|
690
691
|
this._usage = str;
|
|
691
692
|
|
|
@@ -738,7 +739,7 @@ Command.prototype.commandHelp = function(){
|
|
|
738
739
|
, ' Commands:'
|
|
739
740
|
, ''
|
|
740
741
|
, this.commands.map(function(cmd){
|
|
741
|
-
var args = cmd.
|
|
742
|
+
var args = cmd._args.map(function(arg){
|
|
742
743
|
return arg.required
|
|
743
744
|
? '<' + arg.name + '>'
|
|
744
745
|
: '[' + arg.name + ']';
|
|
@@ -747,7 +748,7 @@ Command.prototype.commandHelp = function(){
|
|
|
747
748
|
return pad(cmd._name
|
|
748
749
|
+ (cmd.options.length
|
|
749
750
|
? ' [options]'
|
|
750
|
-
: '') + ' ' + args,
|
|
751
|
+
: '') + ' ' + args, 22)
|
|
751
752
|
+ (cmd.description()
|
|
752
753
|
? ' ' + cmd.description()
|
|
753
754
|
: '');
|
package/package.json
CHANGED