commander 8.0.0 → 8.1.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/Readme.md +11 -11
- package/lib/argument.js +16 -0
- package/lib/command.js +106 -110
- package/package.json +1 -1
- package/typings/index.d.ts +103 -77
package/Readme.md
CHANGED
|
@@ -113,7 +113,7 @@ By default options on the command line are not positional, and can be specified
|
|
|
113
113
|
### Common option types, boolean and value
|
|
114
114
|
|
|
115
115
|
The two most used option types are a boolean option, and an option which takes its value
|
|
116
|
-
from the following argument (declared with angle brackets like `--expect <value>`). Both are `undefined` unless specified on command line.
|
|
116
|
+
from the following argument (declared with angle brackets like `--expect <value>`). Both are `undefined` unless specified on command line.
|
|
117
117
|
|
|
118
118
|
Example file: [options-common.js](./examples/options-common.js)
|
|
119
119
|
|
|
@@ -426,7 +426,7 @@ program
|
|
|
426
426
|
.addCommand(build.makeBuildCommand());
|
|
427
427
|
```
|
|
428
428
|
|
|
429
|
-
Configuration options can be passed with the call to `.command()` and `.addCommand()`. Specifying `hidden: true` will
|
|
429
|
+
Configuration options can be passed with the call to `.command()` and `.addCommand()`. Specifying `hidden: true` will
|
|
430
430
|
remove the command from the generated help output. Specifying `isDefault: true` will run the subcommand if no other
|
|
431
431
|
subcommand is specified ([example](./examples/defaultCommand.js)).
|
|
432
432
|
|
|
@@ -436,7 +436,7 @@ For subcommands, you can specify the argument syntax in the call to `.command()`
|
|
|
436
436
|
is the only method usable for subcommands implemented using a stand-alone executable, but for other subcommands
|
|
437
437
|
you can instead use the following method.
|
|
438
438
|
|
|
439
|
-
To configure a command, you can use `.argument()` to specify each expected command-argument.
|
|
439
|
+
To configure a command, you can use `.argument()` to specify each expected command-argument.
|
|
440
440
|
You supply the argument name and an optional description. The argument may be `<required>` or `[optional]`.
|
|
441
441
|
You can specify a default value for an optional command-argument.
|
|
442
442
|
|
|
@@ -513,7 +513,7 @@ program
|
|
|
513
513
|
### Action handler
|
|
514
514
|
|
|
515
515
|
The action handler gets passed a parameter for each command-argument you declared, and two additional parameters
|
|
516
|
-
which are the parsed options and the command object itself.
|
|
516
|
+
which are the parsed options and the command object itself.
|
|
517
517
|
|
|
518
518
|
Example file: [thank.js](./examples/thank.js)
|
|
519
519
|
|
|
@@ -630,7 +630,7 @@ shell spawn --help
|
|
|
630
630
|
|
|
631
631
|
### Custom help
|
|
632
632
|
|
|
633
|
-
You can add extra text to be displayed along with the built-in help.
|
|
633
|
+
You can add extra text to be displayed along with the built-in help.
|
|
634
634
|
|
|
635
635
|
Example file: [custom-help](./examples/custom-help)
|
|
636
636
|
|
|
@@ -664,7 +664,7 @@ The positions in order displayed are:
|
|
|
664
664
|
- `after`: display extra information after built-in help
|
|
665
665
|
- `afterAll`: add to the program for a global footer (epilog)
|
|
666
666
|
|
|
667
|
-
The positions "beforeAll" and "afterAll" apply to the command and all its subcommands.
|
|
667
|
+
The positions "beforeAll" and "afterAll" apply to the command and all its subcommands.
|
|
668
668
|
|
|
669
669
|
The second parameter can be a string, or a function returning a string. The function is passed a context object for your convenience. The properties are:
|
|
670
670
|
|
|
@@ -673,7 +673,7 @@ The second parameter can be a string, or a function returning a string. The func
|
|
|
673
673
|
|
|
674
674
|
### Display help after errors
|
|
675
675
|
|
|
676
|
-
The default behaviour for usage errors is to just display a short error message.
|
|
676
|
+
The default behaviour for usage errors is to just display a short error message.
|
|
677
677
|
You can change the behaviour to show the full help or a custom help message after an error.
|
|
678
678
|
|
|
679
679
|
```js
|
|
@@ -747,7 +747,7 @@ There are methods getting the visible lists of arguments, options, and subcomman
|
|
|
747
747
|
|
|
748
748
|
Example file: [configure-help.js](./examples/configure-help.js)
|
|
749
749
|
|
|
750
|
-
```
|
|
750
|
+
```js
|
|
751
751
|
program.configureHelp({
|
|
752
752
|
sortSubcommands: true,
|
|
753
753
|
subcommandTerm: (cmd) => cmd.name() // Just show the name, instead of short usage.
|
|
@@ -809,7 +809,7 @@ program subcommand -b
|
|
|
809
809
|
|
|
810
810
|
By default options are recognised before and after command-arguments. To only process options that come
|
|
811
811
|
before the command-arguments, use `.passThroughOptions()`. This lets you pass the arguments and following options through to another program
|
|
812
|
-
without needing to use `--` to end the option processing.
|
|
812
|
+
without needing to use `--` to end the option processing.
|
|
813
813
|
To use pass through options in a subcommand, the program needs to enable positional options.
|
|
814
814
|
|
|
815
815
|
Example file: [pass-through-options.js](./examples/pass-through-options.js)
|
|
@@ -826,7 +826,7 @@ By default the option processing shows an error for an unknown option. To have a
|
|
|
826
826
|
By default the argument processing does not display an error for more command-arguments than expected.
|
|
827
827
|
To display an error for excess arguments, use`.allowExcessArguments(false)`.
|
|
828
828
|
|
|
829
|
-
### Legacy options as properties
|
|
829
|
+
### Legacy options as properties
|
|
830
830
|
|
|
831
831
|
Before Commander 7, the option values were stored as properties on the command.
|
|
832
832
|
This was convenient to code but the downside was possible clashes with
|
|
@@ -986,7 +986,7 @@ Examples:
|
|
|
986
986
|
$ deploy exec sequential
|
|
987
987
|
$ deploy exec async`
|
|
988
988
|
);
|
|
989
|
-
|
|
989
|
+
|
|
990
990
|
program.parse(process.argv);
|
|
991
991
|
```
|
|
992
992
|
|
package/lib/argument.js
CHANGED
|
@@ -109,6 +109,22 @@ class Argument {
|
|
|
109
109
|
};
|
|
110
110
|
return this;
|
|
111
111
|
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Make option-argument required.
|
|
115
|
+
*/
|
|
116
|
+
argRequired() {
|
|
117
|
+
this.required = true;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Make option-argument optional.
|
|
123
|
+
*/
|
|
124
|
+
argOptional() {
|
|
125
|
+
this.required = false;
|
|
126
|
+
return this;
|
|
127
|
+
}
|
|
112
128
|
}
|
|
113
129
|
|
|
114
130
|
/**
|
package/lib/command.js
CHANGED
|
@@ -74,24 +74,52 @@ class Command extends EventEmitter {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
|
-
*
|
|
77
|
+
* Copy settings that are useful to have in common across root command and subcommands.
|
|
78
78
|
*
|
|
79
|
-
*
|
|
79
|
+
* (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
|
|
80
80
|
*
|
|
81
|
-
*
|
|
81
|
+
* @param {Command} sourceCommand
|
|
82
|
+
* @return {Command} returns `this` for executable command
|
|
83
|
+
*/
|
|
84
|
+
copyInheritedSettings(sourceCommand) {
|
|
85
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
86
|
+
this._hasHelpOption = sourceCommand._hasHelpOption;
|
|
87
|
+
this._helpFlags = sourceCommand._helpFlags;
|
|
88
|
+
this._helpDescription = sourceCommand._helpDescription;
|
|
89
|
+
this._helpShortFlag = sourceCommand._helpShortFlag;
|
|
90
|
+
this._helpLongFlag = sourceCommand._helpLongFlag;
|
|
91
|
+
this._helpCommandName = sourceCommand._helpCommandName;
|
|
92
|
+
this._helpCommandnameAndArgs = sourceCommand._helpCommandnameAndArgs;
|
|
93
|
+
this._helpCommandDescription = sourceCommand._helpCommandDescription;
|
|
94
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
95
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
96
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
97
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
98
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
99
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
100
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
101
|
+
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Define a command.
|
|
82
107
|
*
|
|
83
|
-
*
|
|
84
|
-
* program
|
|
85
|
-
* .command('clone <source> [destination]')
|
|
86
|
-
* .description('clone a repository into a newly created directory')
|
|
87
|
-
* .action((source, destination) => {
|
|
88
|
-
* console.log('clone command called');
|
|
89
|
-
* });
|
|
108
|
+
* There are two styles of command: pay attention to where to put the description.
|
|
90
109
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
110
|
+
* @example
|
|
111
|
+
* // Command implemented using action handler (description is supplied separately to `.command`)
|
|
112
|
+
* program
|
|
113
|
+
* .command('clone <source> [destination]')
|
|
114
|
+
* .description('clone a repository into a newly created directory')
|
|
115
|
+
* .action((source, destination) => {
|
|
116
|
+
* console.log('clone command called');
|
|
117
|
+
* });
|
|
118
|
+
*
|
|
119
|
+
* // Command implemented using separate executable file (description is second parameter to `.command`)
|
|
120
|
+
* program
|
|
121
|
+
* .command('start <service>', 'start named service')
|
|
122
|
+
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
|
95
123
|
*
|
|
96
124
|
* @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
97
125
|
* @param {Object|string} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
|
|
@@ -108,37 +136,19 @@ class Command extends EventEmitter {
|
|
|
108
136
|
}
|
|
109
137
|
opts = opts || {};
|
|
110
138
|
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
111
|
-
const cmd = this.createCommand(name);
|
|
112
139
|
|
|
140
|
+
const cmd = this.createCommand(name);
|
|
113
141
|
if (desc) {
|
|
114
142
|
cmd.description(desc);
|
|
115
143
|
cmd._executableHandler = true;
|
|
116
144
|
}
|
|
117
145
|
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
118
|
-
|
|
119
|
-
cmd._outputConfiguration = this._outputConfiguration;
|
|
120
|
-
|
|
121
146
|
cmd._hidden = !!(opts.noHelp || opts.hidden); // noHelp is deprecated old name for hidden
|
|
122
|
-
cmd._hasHelpOption = this._hasHelpOption;
|
|
123
|
-
cmd._helpFlags = this._helpFlags;
|
|
124
|
-
cmd._helpDescription = this._helpDescription;
|
|
125
|
-
cmd._helpShortFlag = this._helpShortFlag;
|
|
126
|
-
cmd._helpLongFlag = this._helpLongFlag;
|
|
127
|
-
cmd._helpCommandName = this._helpCommandName;
|
|
128
|
-
cmd._helpCommandnameAndArgs = this._helpCommandnameAndArgs;
|
|
129
|
-
cmd._helpCommandDescription = this._helpCommandDescription;
|
|
130
|
-
cmd._helpConfiguration = this._helpConfiguration;
|
|
131
|
-
cmd._exitCallback = this._exitCallback;
|
|
132
|
-
cmd._storeOptionsAsProperties = this._storeOptionsAsProperties;
|
|
133
|
-
cmd._combineFlagAndOptionalValue = this._combineFlagAndOptionalValue;
|
|
134
|
-
cmd._allowExcessArguments = this._allowExcessArguments;
|
|
135
|
-
cmd._enablePositionalOptions = this._enablePositionalOptions;
|
|
136
|
-
cmd._showHelpAfterError = this._showHelpAfterError;
|
|
137
|
-
|
|
138
147
|
cmd._executableFile = opts.executableFile || null; // Custom name for executable file, set missing to null to match constructor
|
|
139
148
|
if (args) cmd.arguments(args);
|
|
140
149
|
this.commands.push(cmd);
|
|
141
150
|
cmd.parent = this;
|
|
151
|
+
cmd.copyInheritedSettings(this);
|
|
142
152
|
|
|
143
153
|
if (desc) return this;
|
|
144
154
|
return cmd;
|
|
@@ -190,14 +200,14 @@ class Command extends EventEmitter {
|
|
|
190
200
|
*
|
|
191
201
|
* The configuration properties are all functions:
|
|
192
202
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
203
|
+
* // functions to change where being written, stdout and stderr
|
|
204
|
+
* writeOut(str)
|
|
205
|
+
* writeErr(str)
|
|
206
|
+
* // matching functions to specify width for wrapping help
|
|
207
|
+
* getOutHelpWidth()
|
|
208
|
+
* getErrHelpWidth()
|
|
209
|
+
* // functions based on what is being written out
|
|
210
|
+
* outputError(str, write) // used for displaying errors, and not used for displaying help
|
|
201
211
|
*
|
|
202
212
|
* @param {Object} [configuration] - configuration options
|
|
203
213
|
* @return {Command|Object} `this` command for chaining, or stored configuration
|
|
@@ -278,9 +288,8 @@ class Command extends EventEmitter {
|
|
|
278
288
|
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
279
289
|
*
|
|
280
290
|
* @example
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* program.argument('[output-file]');
|
|
291
|
+
* program.argument('<input-file>');
|
|
292
|
+
* program.argument('[output-file]');
|
|
284
293
|
*
|
|
285
294
|
* @param {string} name
|
|
286
295
|
* @param {string} [description]
|
|
@@ -305,8 +314,7 @@ class Command extends EventEmitter {
|
|
|
305
314
|
* See also .argument().
|
|
306
315
|
*
|
|
307
316
|
* @example
|
|
308
|
-
*
|
|
309
|
-
* program.arguments('<cmd> [env]');
|
|
317
|
+
* program.arguments('<cmd> [env]');
|
|
310
318
|
*
|
|
311
319
|
* @param {string} names
|
|
312
320
|
* @return {Command} `this` command for chaining
|
|
@@ -438,14 +446,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
438
446
|
/**
|
|
439
447
|
* Register callback `fn` for the command.
|
|
440
448
|
*
|
|
441
|
-
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
* });
|
|
449
|
+
* @example
|
|
450
|
+
* program
|
|
451
|
+
* .command('help')
|
|
452
|
+
* .description('display verbose help')
|
|
453
|
+
* .action(function() {
|
|
454
|
+
* // output help here
|
|
455
|
+
* });
|
|
449
456
|
*
|
|
450
457
|
* @param {Function} fn
|
|
451
458
|
* @return {Command} `this` command for chaining
|
|
@@ -584,41 +591,40 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
584
591
|
* separated by comma, a pipe or space. The following are all valid
|
|
585
592
|
* all will output this way when `--help` is used.
|
|
586
593
|
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
* Examples:
|
|
594
|
+
* "-p, --pepper"
|
|
595
|
+
* "-p|--pepper"
|
|
596
|
+
* "-p --pepper"
|
|
592
597
|
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
598
|
+
* @example
|
|
599
|
+
* // simple boolean defaulting to undefined
|
|
600
|
+
* program.option('-p, --pepper', 'add pepper');
|
|
595
601
|
*
|
|
596
|
-
*
|
|
597
|
-
*
|
|
602
|
+
* program.pepper
|
|
603
|
+
* // => undefined
|
|
598
604
|
*
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
605
|
+
* --pepper
|
|
606
|
+
* program.pepper
|
|
607
|
+
* // => true
|
|
602
608
|
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
609
|
+
* // simple boolean defaulting to true (unless non-negated option is also defined)
|
|
610
|
+
* program.option('-C, --no-cheese', 'remove cheese');
|
|
605
611
|
*
|
|
606
|
-
*
|
|
607
|
-
*
|
|
612
|
+
* program.cheese
|
|
613
|
+
* // => true
|
|
608
614
|
*
|
|
609
|
-
*
|
|
610
|
-
*
|
|
611
|
-
*
|
|
615
|
+
* --no-cheese
|
|
616
|
+
* program.cheese
|
|
617
|
+
* // => false
|
|
612
618
|
*
|
|
613
|
-
*
|
|
614
|
-
*
|
|
619
|
+
* // required argument
|
|
620
|
+
* program.option('-C, --chdir <path>', 'change the working directory');
|
|
615
621
|
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
622
|
+
* --chdir /tmp
|
|
623
|
+
* program.chdir
|
|
624
|
+
* // => "/tmp"
|
|
619
625
|
*
|
|
620
|
-
*
|
|
621
|
-
*
|
|
626
|
+
* // optional argument
|
|
627
|
+
* program.option('-c, --cheese [type]', 'add cheese [marble]');
|
|
622
628
|
*
|
|
623
629
|
* @param {string} flags
|
|
624
630
|
* @param {string} [description]
|
|
@@ -651,11 +657,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
651
657
|
/**
|
|
652
658
|
* Alter parsing of short flags with optional values.
|
|
653
659
|
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
* .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
660
|
+
* @example
|
|
661
|
+
* // for `.option('-f,--flag [value]'):
|
|
662
|
+
* program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
663
|
+
* program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
659
664
|
*
|
|
660
665
|
* @param {Boolean} [combine=true] - if `true` or omitted, an optional value can be specified directly after the flag.
|
|
661
666
|
*/
|
|
@@ -824,11 +829,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
824
829
|
* The default expectation is that the arguments are from node and have the application as argv[0]
|
|
825
830
|
* and the script being run in argv[1], with user parameters after that.
|
|
826
831
|
*
|
|
827
|
-
*
|
|
828
|
-
*
|
|
829
|
-
*
|
|
830
|
-
*
|
|
831
|
-
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
832
|
+
* @example
|
|
833
|
+
* program.parse(process.argv);
|
|
834
|
+
* program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
|
|
835
|
+
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
832
836
|
*
|
|
833
837
|
* @param {string[]} [argv] - optional, defaults to process.argv
|
|
834
838
|
* @param {Object} [parseOptions] - optionally specify style of options with from: node/user/electron
|
|
@@ -851,11 +855,10 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
851
855
|
* The default expectation is that the arguments are from node and have the application as argv[0]
|
|
852
856
|
* and the script being run in argv[1], with user parameters after that.
|
|
853
857
|
*
|
|
854
|
-
*
|
|
855
|
-
*
|
|
856
|
-
*
|
|
857
|
-
*
|
|
858
|
-
* await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
858
|
+
* @example
|
|
859
|
+
* await program.parseAsync(process.argv);
|
|
860
|
+
* await program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
|
|
861
|
+
* await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
859
862
|
*
|
|
860
863
|
* @param {string[]} [argv]
|
|
861
864
|
* @param {Object} [parseOptions]
|
|
@@ -1245,11 +1248,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1245
1248
|
*
|
|
1246
1249
|
* Examples:
|
|
1247
1250
|
*
|
|
1248
|
-
*
|
|
1249
|
-
*
|
|
1250
|
-
*
|
|
1251
|
-
*
|
|
1252
|
-
*
|
|
1251
|
+
* argv => operands, unknown
|
|
1252
|
+
* --known kkk op => [op], []
|
|
1253
|
+
* op --known kkk => [op], []
|
|
1254
|
+
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
1255
|
+
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
1253
1256
|
*
|
|
1254
1257
|
* @param {String[]} argv
|
|
1255
1258
|
* @return {{operands: String[], unknown: String[]}}
|
|
@@ -1659,14 +1662,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1659
1662
|
}
|
|
1660
1663
|
const context = this._getHelpContext(contextOptions);
|
|
1661
1664
|
|
|
1662
|
-
|
|
1663
|
-
let command = this;
|
|
1664
|
-
while (command) {
|
|
1665
|
-
groupListeners.push(command); // ordered from current command to root
|
|
1666
|
-
command = command.parent;
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
groupListeners.slice().reverse().forEach(command => command.emit('beforeAllHelp', context));
|
|
1665
|
+
getCommandAndParents(this).reverse().forEach(command => command.emit('beforeAllHelp', context));
|
|
1670
1666
|
this.emit('beforeHelp', context);
|
|
1671
1667
|
|
|
1672
1668
|
let helpInformation = this.helpInformation(context);
|
|
@@ -1680,7 +1676,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1680
1676
|
|
|
1681
1677
|
this.emit(this._helpLongFlag); // deprecated
|
|
1682
1678
|
this.emit('afterHelp', context);
|
|
1683
|
-
|
|
1679
|
+
getCommandAndParents(this).forEach(command => command.emit('afterAllHelp', context));
|
|
1684
1680
|
};
|
|
1685
1681
|
|
|
1686
1682
|
/**
|
package/package.json
CHANGED
package/typings/index.d.ts
CHANGED
|
@@ -13,9 +13,9 @@ export class CommanderError extends Error {
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Constructs the CommanderError class
|
|
16
|
-
* @param
|
|
17
|
-
* @param
|
|
18
|
-
* @param
|
|
16
|
+
* @param exitCode - suggested exit code which could be used with process.exit
|
|
17
|
+
* @param code - an id string representing the error
|
|
18
|
+
* @param message - human-readable description of the error
|
|
19
19
|
* @constructor
|
|
20
20
|
*/
|
|
21
21
|
constructor(exitCode: number, code: string, message: string);
|
|
@@ -24,7 +24,7 @@ export class CommanderError extends Error {
|
|
|
24
24
|
export class InvalidArgumentError extends CommanderError {
|
|
25
25
|
/**
|
|
26
26
|
* Constructs the InvalidArgumentError class
|
|
27
|
-
* @param
|
|
27
|
+
* @param message - explanation of why argument is invalid
|
|
28
28
|
* @constructor
|
|
29
29
|
*/
|
|
30
30
|
constructor(message: string);
|
|
@@ -40,9 +40,6 @@ export class Argument {
|
|
|
40
40
|
* Initialize a new command argument with the given name and description.
|
|
41
41
|
* The default is that the argument is required, and you can explicitly
|
|
42
42
|
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
43
|
-
*
|
|
44
|
-
* @param {string} name
|
|
45
|
-
* @param {string} [description]
|
|
46
43
|
*/
|
|
47
44
|
constructor(arg: string, description?: string);
|
|
48
45
|
|
|
@@ -66,6 +63,15 @@ export class Argument {
|
|
|
66
63
|
*/
|
|
67
64
|
choices(values: string[]): this;
|
|
68
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Make option-argument required.
|
|
68
|
+
*/
|
|
69
|
+
argRequired(): this;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Make option-argument optional.
|
|
73
|
+
*/
|
|
74
|
+
argOptional(): this;
|
|
69
75
|
}
|
|
70
76
|
|
|
71
77
|
export class Option {
|
|
@@ -241,12 +247,12 @@ export class Command {
|
|
|
241
247
|
*
|
|
242
248
|
* @example
|
|
243
249
|
* ```ts
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
+
* program
|
|
251
|
+
* .command('clone <source> [destination]')
|
|
252
|
+
* .description('clone a repository into a newly created directory')
|
|
253
|
+
* .action((source, destination) => {
|
|
254
|
+
* console.log('clone command called');
|
|
255
|
+
* });
|
|
250
256
|
* ```
|
|
251
257
|
*
|
|
252
258
|
* @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
@@ -306,9 +312,10 @@ export class Command {
|
|
|
306
312
|
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
307
313
|
*
|
|
308
314
|
* @example
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
315
|
+
* ```
|
|
316
|
+
* program.argument('<input-file>');
|
|
317
|
+
* program.argument('[output-file]');
|
|
318
|
+
* ```
|
|
312
319
|
*
|
|
313
320
|
* @returns `this` command for chaining
|
|
314
321
|
*/
|
|
@@ -328,8 +335,9 @@ export class Command {
|
|
|
328
335
|
* See also .argument().
|
|
329
336
|
*
|
|
330
337
|
* @example
|
|
331
|
-
*
|
|
332
|
-
*
|
|
338
|
+
* ```
|
|
339
|
+
* program.arguments('<cmd> [env]');
|
|
340
|
+
* ```
|
|
333
341
|
*
|
|
334
342
|
* @returns `this` command for chaining
|
|
335
343
|
*/
|
|
@@ -338,9 +346,12 @@ export class Command {
|
|
|
338
346
|
/**
|
|
339
347
|
* Override default decision whether to add implicit help command.
|
|
340
348
|
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
349
|
+
* @example
|
|
350
|
+
* ```
|
|
351
|
+
* addHelpCommand() // force on
|
|
352
|
+
* addHelpCommand(false); // force off
|
|
353
|
+
* addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
|
|
354
|
+
* ```
|
|
344
355
|
*
|
|
345
356
|
* @returns `this` command for chaining
|
|
346
357
|
*/
|
|
@@ -375,20 +386,28 @@ export class Command {
|
|
|
375
386
|
* applications. You can also customise the display of errors by overriding outputError.
|
|
376
387
|
*
|
|
377
388
|
* The configuration properties are all functions:
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
389
|
+
* ```
|
|
390
|
+
* // functions to change where being written, stdout and stderr
|
|
391
|
+
* writeOut(str)
|
|
392
|
+
* writeErr(str)
|
|
393
|
+
* // matching functions to specify width for wrapping help
|
|
394
|
+
* getOutHelpWidth()
|
|
395
|
+
* getErrHelpWidth()
|
|
396
|
+
* // functions based on what is being written out
|
|
397
|
+
* outputError(str, write) // used for displaying errors, and not used for displaying help
|
|
398
|
+
* ```
|
|
387
399
|
*/
|
|
388
400
|
configureOutput(configuration: OutputConfiguration): this;
|
|
389
401
|
/** Get configuration */
|
|
390
402
|
configureOutput(): OutputConfiguration;
|
|
391
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Copy settings that are useful to have in common across root command and subcommands.
|
|
406
|
+
*
|
|
407
|
+
* (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
|
|
408
|
+
*/
|
|
409
|
+
copyInheritedSettings(sourceCommand: Command): this;
|
|
410
|
+
|
|
392
411
|
/**
|
|
393
412
|
* Display the help or a custom message after an error occurs.
|
|
394
413
|
*/
|
|
@@ -398,12 +417,14 @@ export class Command {
|
|
|
398
417
|
* Register callback `fn` for the command.
|
|
399
418
|
*
|
|
400
419
|
* @example
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
420
|
+
* ```
|
|
421
|
+
* program
|
|
422
|
+
* .command('help')
|
|
423
|
+
* .description('display verbose help')
|
|
424
|
+
* .action(function() {
|
|
425
|
+
* // output help here
|
|
426
|
+
* });
|
|
427
|
+
* ```
|
|
407
428
|
*
|
|
408
429
|
* @returns `this` command for chaining
|
|
409
430
|
*/
|
|
@@ -417,37 +438,39 @@ export class Command {
|
|
|
417
438
|
* separated by comma, a pipe or space. The following are all valid
|
|
418
439
|
* all will output this way when `--help` is used.
|
|
419
440
|
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
441
|
+
* "-p, --pepper"
|
|
442
|
+
* "-p|--pepper"
|
|
443
|
+
* "-p --pepper"
|
|
423
444
|
*
|
|
424
445
|
* @example
|
|
425
|
-
*
|
|
426
|
-
*
|
|
446
|
+
* ```
|
|
447
|
+
* // simple boolean defaulting to false
|
|
448
|
+
* program.option('-p, --pepper', 'add pepper');
|
|
427
449
|
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
*
|
|
450
|
+
* --pepper
|
|
451
|
+
* program.pepper
|
|
452
|
+
* // => Boolean
|
|
431
453
|
*
|
|
432
|
-
*
|
|
433
|
-
*
|
|
454
|
+
* // simple boolean defaulting to true
|
|
455
|
+
* program.option('-C, --no-cheese', 'remove cheese');
|
|
434
456
|
*
|
|
435
|
-
*
|
|
436
|
-
*
|
|
457
|
+
* program.cheese
|
|
458
|
+
* // => true
|
|
437
459
|
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
460
|
+
* --no-cheese
|
|
461
|
+
* program.cheese
|
|
462
|
+
* // => false
|
|
441
463
|
*
|
|
442
|
-
*
|
|
443
|
-
*
|
|
464
|
+
* // required argument
|
|
465
|
+
* program.option('-C, --chdir <path>', 'change the working directory');
|
|
444
466
|
*
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
467
|
+
* --chdir /tmp
|
|
468
|
+
* program.chdir
|
|
469
|
+
* // => "/tmp"
|
|
448
470
|
*
|
|
449
|
-
*
|
|
450
|
-
*
|
|
471
|
+
* // optional argument
|
|
472
|
+
* program.option('-c, --cheese [type]', 'add cheese [marble]');
|
|
473
|
+
* ```
|
|
451
474
|
*
|
|
452
475
|
* @returns `this` command for chaining
|
|
453
476
|
*/
|
|
@@ -507,9 +530,11 @@ export class Command {
|
|
|
507
530
|
* Alter parsing of short flags with optional values.
|
|
508
531
|
*
|
|
509
532
|
* @example
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
533
|
+
* ```
|
|
534
|
+
* // for `.option('-f,--flag [value]'):
|
|
535
|
+
* .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
536
|
+
* .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
537
|
+
* ```
|
|
513
538
|
*
|
|
514
539
|
* @returns `this` command for chaining
|
|
515
540
|
*/
|
|
@@ -556,11 +581,12 @@ export class Command {
|
|
|
556
581
|
* The default expectation is that the arguments are from node and have the application as argv[0]
|
|
557
582
|
* and the script being run in argv[1], with user parameters after that.
|
|
558
583
|
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```
|
|
586
|
+
* program.parse(process.argv);
|
|
587
|
+
* program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
|
|
588
|
+
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
589
|
+
* ```
|
|
564
590
|
*
|
|
565
591
|
* @returns `this` command for chaining
|
|
566
592
|
*/
|
|
@@ -574,11 +600,12 @@ export class Command {
|
|
|
574
600
|
* The default expectation is that the arguments are from node and have the application as argv[0]
|
|
575
601
|
* and the script being run in argv[1], with user parameters after that.
|
|
576
602
|
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
603
|
+
* @example
|
|
604
|
+
* ```
|
|
605
|
+
* program.parseAsync(process.argv);
|
|
606
|
+
* program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
|
|
607
|
+
* program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
608
|
+
* ```
|
|
582
609
|
*
|
|
583
610
|
* @returns Promise
|
|
584
611
|
*/
|
|
@@ -588,12 +615,11 @@ export class Command {
|
|
|
588
615
|
* Parse options from `argv` removing known options,
|
|
589
616
|
* and return argv split into operands and unknown arguments.
|
|
590
617
|
*
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
618
|
+
* argv => operands, unknown
|
|
619
|
+
* --known kkk op => [op], []
|
|
620
|
+
* op --known kkk => [op], []
|
|
621
|
+
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
622
|
+
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
597
623
|
*/
|
|
598
624
|
parseOptions(argv: string[]): ParseOptionsResult;
|
|
599
625
|
|