commander 12.0.0-1 → 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 +13 -10
- 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
|
|
@@ -1098,8 +1100,9 @@ program.error('Custom processing has failed', { exitCode: 2, code: 'my.custom.er
|
|
|
1098
1100
|
By default, Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override
|
|
1099
1101
|
this behaviour and optionally supply a callback. The default override throws a `CommanderError`.
|
|
1100
1102
|
|
|
1101
|
-
The override callback is passed a `CommanderError` with properties `exitCode` number, `code` string, and `message`.
|
|
1102
|
-
|
|
1103
|
+
The override callback is passed a `CommanderError` with properties `exitCode` number, `code` string, and `message`.
|
|
1104
|
+
Commander expects the callback to terminate the normal program flow, and will call `process.exit` if the callback returns.
|
|
1105
|
+
The normal display of error messages or version or help is not affected by the override which is called after the display.
|
|
1103
1106
|
|
|
1104
1107
|
```js
|
|
1105
1108
|
program.exitOverride();
|
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;
|