commander 12.0.0 → 12.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 +10 -8
- package/esm.mjs +1 -1
- package/lib/argument.js +9 -5
- package/lib/command.js +406 -196
- package/lib/error.js +0 -4
- package/lib/help.js +101 -38
- package/lib/option.js +11 -8
- package/lib/suggestSimilar.js +5 -4
- package/package.json +23 -19
- package/typings/index.d.ts +110 -40
package/Readme.md
CHANGED
|
@@ -955,22 +955,24 @@ program.on('option:verbose', function () {
|
|
|
955
955
|
|
|
956
956
|
### .parse() and .parseAsync()
|
|
957
957
|
|
|
958
|
-
|
|
958
|
+
Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
959
959
|
|
|
960
|
-
|
|
960
|
+
Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
961
961
|
|
|
962
|
-
- 'node'
|
|
963
|
-
- 'electron'
|
|
964
|
-
- 'user'
|
|
962
|
+
- `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
963
|
+
- `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
964
|
+
- `'user'`: just user arguments
|
|
965
965
|
|
|
966
966
|
For example:
|
|
967
967
|
|
|
968
968
|
```js
|
|
969
|
-
program.parse(
|
|
970
|
-
program.parse(); //
|
|
971
|
-
program.parse(['
|
|
969
|
+
program.parse(); // parse process.argv and auto-detect electron and special node flags
|
|
970
|
+
program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
|
971
|
+
program.parse(['--port', '80'], { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
972
972
|
```
|
|
973
973
|
|
|
974
|
+
Use parseAsync instead of parse if any of your action handlers are async.
|
|
975
|
+
|
|
974
976
|
If you want to parse multiple times, create a new program each time. Calling parse does not clear out any previous state.
|
|
975
977
|
|
|
976
978
|
### Parsing Configuration
|
package/esm.mjs
CHANGED
package/lib/argument.js
CHANGED
|
@@ -50,7 +50,7 @@ class Argument {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* @package
|
|
53
|
+
* @package
|
|
54
54
|
*/
|
|
55
55
|
|
|
56
56
|
_concatValue(value, previous) {
|
|
@@ -98,7 +98,9 @@ class Argument {
|
|
|
98
98
|
this.argChoices = values.slice();
|
|
99
99
|
this.parseArg = (arg, previous) => {
|
|
100
100
|
if (!this.argChoices.includes(arg)) {
|
|
101
|
-
throw new InvalidArgumentError(
|
|
101
|
+
throw new InvalidArgumentError(
|
|
102
|
+
`Allowed choices are ${this.argChoices.join(', ')}.`,
|
|
103
|
+
);
|
|
102
104
|
}
|
|
103
105
|
if (this.variadic) {
|
|
104
106
|
return this._concatValue(arg, previous);
|
|
@@ -110,6 +112,8 @@ class Argument {
|
|
|
110
112
|
|
|
111
113
|
/**
|
|
112
114
|
* Make argument required.
|
|
115
|
+
*
|
|
116
|
+
* @returns {Argument}
|
|
113
117
|
*/
|
|
114
118
|
argRequired() {
|
|
115
119
|
this.required = true;
|
|
@@ -118,6 +122,8 @@ class Argument {
|
|
|
118
122
|
|
|
119
123
|
/**
|
|
120
124
|
* Make argument optional.
|
|
125
|
+
*
|
|
126
|
+
* @returns {Argument}
|
|
121
127
|
*/
|
|
122
128
|
argOptional() {
|
|
123
129
|
this.required = false;
|
|
@@ -136,9 +142,7 @@ class Argument {
|
|
|
136
142
|
function humanReadableArgName(arg) {
|
|
137
143
|
const nameOutput = arg.name() + (arg.variadic === true ? '...' : '');
|
|
138
144
|
|
|
139
|
-
return arg.required
|
|
140
|
-
? '<' + nameOutput + '>'
|
|
141
|
-
: '[' + nameOutput + ']';
|
|
145
|
+
return arg.required ? '<' + nameOutput + '>' : '[' + nameOutput + ']';
|
|
142
146
|
}
|
|
143
147
|
|
|
144
148
|
exports.Argument = Argument;
|