commander 6.1.0 → 6.2.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 +26 -0
- package/Readme.md +37 -22
- package/index.js +1 -2
- package/package.json +13 -10
- package/typings/index.d.ts +12 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
8
8
|
<!-- markdownlint-disable MD024 -->
|
|
9
9
|
<!-- markdownlint-disable MD004 -->
|
|
10
10
|
|
|
11
|
+
## [6.2.0] (2020-10-25)
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- added 'tsx' file extension for stand-alone executable subcommands ([#1368])
|
|
16
|
+
- documented second parameter to `.description()` to describe command arguments ([#1353])
|
|
17
|
+
- documentation of special cases with options taking varying numbers of option-arguments ([#1332])
|
|
18
|
+
- documentation for terminology ([#1361])
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- add missing TypeScript definition for `.addHelpCommand()' ([#1375])
|
|
23
|
+
- removed blank line after "Arguments:" in help, to match "Options:" and "Commands:" ([#1360])
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- update dependencies
|
|
28
|
+
|
|
11
29
|
## [6.1.0] (2020-08-28)
|
|
12
30
|
|
|
13
31
|
### Added
|
|
@@ -308,8 +326,16 @@ if (program.rawArgs.length < 3) ...
|
|
|
308
326
|
[#1323]: https://github.com/tj/commander.js/pull/1323
|
|
309
327
|
[#1325]: https://github.com/tj/commander.js/pull/1325
|
|
310
328
|
[#1326]: https://github.com/tj/commander.js/pull/1326
|
|
329
|
+
[#1332]: https://github.com/tj/commander.js/pull/1332
|
|
330
|
+
[#1353]: https://github.com/tj/commander.js/pull/1353
|
|
331
|
+
[#1360]: https://github.com/tj/commander.js/pull/1360
|
|
332
|
+
[#1361]: https://github.com/tj/commander.js/pull/1361
|
|
333
|
+
[#1368]: https://github.com/tj/commander.js/pull/1368
|
|
334
|
+
[#1375]: https://github.com/tj/commander.js/pull/1375
|
|
335
|
+
|
|
311
336
|
|
|
312
337
|
[Unreleased]: https://github.com/tj/commander.js/compare/master...develop
|
|
338
|
+
[6.2.0]: https://github.com/tj/commander.js/compare/v6.1.0..v6.2.0
|
|
313
339
|
[6.1.0]: https://github.com/tj/commander.js/compare/v6.0.0..v6.1.0
|
|
314
340
|
[6.0.0]: https://github.com/tj/commander.js/compare/v5.1.0..v6.0.0
|
|
315
341
|
[6.0.0-0]: https://github.com/tj/commander.js/compare/v5.1.0..v6.0.0-0
|
package/Readme.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://npmcharts.com/compare/commander?minimal=true)
|
|
6
6
|
[](https://packagephobia.now.sh/result?p=commander)
|
|
7
7
|
|
|
8
|
-
The complete solution for [node.js](http://nodejs.org) command-line interfaces
|
|
8
|
+
The complete solution for [node.js](http://nodejs.org) command-line interfaces.
|
|
9
9
|
|
|
10
10
|
Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
|
|
|
15
15
|
- [Options](#options)
|
|
16
16
|
- [Common option types, boolean and value](#common-option-types-boolean-and-value)
|
|
17
17
|
- [Default option value](#default-option-value)
|
|
18
|
-
- [Other option types, negatable boolean and
|
|
18
|
+
- [Other option types, negatable boolean and boolean|value](#other-option-types-negatable-boolean-and-booleanvalue)
|
|
19
19
|
- [Custom option processing](#custom-option-processing)
|
|
20
20
|
- [Required option](#required-option)
|
|
21
21
|
- [Variadic option](#variadic-option)
|
|
@@ -46,6 +46,8 @@ Read this in other languages: English | [简体中文](./Readme_zh-CN.md)
|
|
|
46
46
|
- [Support](#support)
|
|
47
47
|
- [Commander for enterprise](#commander-for-enterprise)
|
|
48
48
|
|
|
49
|
+
For information about terms used in this document see: [terminology](./docs/terminology.md)
|
|
50
|
+
|
|
49
51
|
## Installation
|
|
50
52
|
|
|
51
53
|
```bash
|
|
@@ -76,18 +78,17 @@ Options are defined with the `.option()` method, also serving as documentation f
|
|
|
76
78
|
|
|
77
79
|
The options can be accessed as properties on the Command object. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc. See also optional new behaviour to [avoid name clashes](#avoiding-option-name-clashes).
|
|
78
80
|
|
|
79
|
-
Multiple short flags may optionally be combined in a single argument following the dash: boolean flags,
|
|
81
|
+
Multiple short flags may optionally be combined in a single argument following the dash: boolean flags, followed by a single option taking a value (possibly followed by the value).
|
|
80
82
|
For example `-a -b -p 80` may be written as `-ab -p80` or even `-abp80`.
|
|
81
83
|
|
|
82
84
|
You can use `--` to indicate the end of the options, and any remaining arguments will be used without being interpreted.
|
|
83
|
-
This is particularly useful for passing options through to another
|
|
84
|
-
command, like: `do -- git --version`.
|
|
85
85
|
|
|
86
|
-
Options on the command line are not positional, and can be specified before or after other
|
|
86
|
+
Options on the command line are not positional, and can be specified before or after other arguments.
|
|
87
87
|
|
|
88
88
|
### Common option types, boolean and value
|
|
89
89
|
|
|
90
|
-
The two most used option types are a boolean
|
|
90
|
+
The two most used option types are a boolean option, and an option which takes its value
|
|
91
|
+
from the following argument (declared with angle brackets like `--expect <value>`). Both are `undefined` unless specified on command line.
|
|
91
92
|
|
|
92
93
|
Example file: [options-common.js](./examples/options-common.js)
|
|
93
94
|
|
|
@@ -145,13 +146,13 @@ $ pizza-options --cheese stilton
|
|
|
145
146
|
cheese: stilton
|
|
146
147
|
```
|
|
147
148
|
|
|
148
|
-
### Other option types, negatable boolean and
|
|
149
|
+
### Other option types, negatable boolean and boolean|value
|
|
149
150
|
|
|
150
|
-
You can
|
|
151
|
+
You can define a boolean option long name with a leading `no-` to set the option value to false when used.
|
|
151
152
|
Defined alone this also makes the option true by default.
|
|
152
153
|
|
|
153
154
|
If you define `--foo` first, adding `--no-foo` does not change the default value from what it would
|
|
154
|
-
otherwise be. You can specify a default boolean value for a boolean
|
|
155
|
+
otherwise be. You can specify a default boolean value for a boolean option and it can be overridden on command line.
|
|
155
156
|
|
|
156
157
|
Example file: [options-negatable.js](./examples/options-negatable.js)
|
|
157
158
|
|
|
@@ -178,9 +179,10 @@ $ pizza-options --no-sauce --no-cheese
|
|
|
178
179
|
You ordered a pizza with no sauce and no cheese
|
|
179
180
|
```
|
|
180
181
|
|
|
181
|
-
You can specify an option which
|
|
182
|
+
You can specify an option which may be used as a boolean option but may optionally take an option-argument
|
|
183
|
+
(declared with square brackets like `--optional [value]`).
|
|
182
184
|
|
|
183
|
-
Example file: [options-
|
|
185
|
+
Example file: [options-boolean-or-value.js](./examples/options-boolean-or-value.js)
|
|
184
186
|
|
|
185
187
|
```js
|
|
186
188
|
program
|
|
@@ -202,14 +204,16 @@ $ pizza-options --cheese mozzarella
|
|
|
202
204
|
add cheese type mozzarella
|
|
203
205
|
```
|
|
204
206
|
|
|
207
|
+
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
|
|
208
|
+
|
|
205
209
|
### Custom option processing
|
|
206
210
|
|
|
207
|
-
You may specify a function to do custom processing of option
|
|
208
|
-
previous value for the option. It returns the new value for the option.
|
|
211
|
+
You may specify a function to do custom processing of option-arguments. The callback function receives two parameters,
|
|
212
|
+
the user specified option-argument and the previous value for the option. It returns the new value for the option.
|
|
209
213
|
|
|
210
|
-
This allows you to coerce the option
|
|
214
|
+
This allows you to coerce the option-argument to the desired type, or accumulate values, or do entirely custom processing.
|
|
211
215
|
|
|
212
|
-
You can optionally specify the default/starting value for the option after the function.
|
|
216
|
+
You can optionally specify the default/starting value for the option after the function parameter.
|
|
213
217
|
|
|
214
218
|
Example file: [options-custom-processing.js](./examples/options-custom-processing.js)
|
|
215
219
|
|
|
@@ -282,7 +286,7 @@ error: required option '-c, --cheese <type>' not specified
|
|
|
282
286
|
### Variadic option
|
|
283
287
|
|
|
284
288
|
You may make an option variadic by appending `...` to the value placeholder when declaring the option. On the command line you
|
|
285
|
-
can then specify multiple option
|
|
289
|
+
can then specify multiple option-arguments, and the parsed option value will be an array. The extra arguments
|
|
286
290
|
are read until the first argument starting with a dash. The special argument `--` stops option processing entirely. If a value
|
|
287
291
|
is specified in the same argument as the option then no further values are read.
|
|
288
292
|
|
|
@@ -311,6 +315,8 @@ Options: { number: [ '1', '2', '3' ], letter: true }
|
|
|
311
315
|
Remaining arguments: [ 'operand' ]
|
|
312
316
|
```
|
|
313
317
|
|
|
318
|
+
For information about possible ambiguous cases, see [options taking varying arguments](./docs/options-taking-varying-arguments.md).
|
|
319
|
+
|
|
314
320
|
### Version option
|
|
315
321
|
|
|
316
322
|
The optional `version` method adds handling for displaying the command version. The default option flags are `-V` and `--version`, and when present the command prints the version number and exits.
|
|
@@ -335,7 +341,7 @@ program.version('0.0.1', '-v, --vers', 'output the current version');
|
|
|
335
341
|
|
|
336
342
|
You can specify (sub)commands using `.command()` or `.addCommand()`. There are two ways these can be implemented: using an action handler attached to the command, or as a stand-alone executable file (described in more detail later). The subcommands may be nested ([example](./examples/nestedCommands.js)).
|
|
337
343
|
|
|
338
|
-
In the first parameter to `.command()` you specify the command name and any command
|
|
344
|
+
In the first parameter to `.command()` you specify the command name and any command-arguments. The arguments may be `<required>` or `[optional]`, and the last argument may also be `variadic...`.
|
|
339
345
|
|
|
340
346
|
You can use `.addCommand()` to add an already configured subcommand to the program.
|
|
341
347
|
|
|
@@ -363,11 +369,16 @@ program
|
|
|
363
369
|
.addCommand(build.makeBuildCommand());
|
|
364
370
|
```
|
|
365
371
|
|
|
366
|
-
Configuration options can be passed with the call to `.command()` and `.addCommand()`. Specifying `
|
|
372
|
+
Configuration options can be passed with the call to `.command()` and `.addCommand()`. Specifying `hidden: true` will
|
|
373
|
+
remove the command from the generated help output. Specifying `isDefault: true` will run the subcommand if no other
|
|
374
|
+
subcommand is specified ([example](./examples/defaultCommand.js)).
|
|
367
375
|
|
|
368
376
|
### Specify the argument syntax
|
|
369
377
|
|
|
370
|
-
You use `.arguments` to specify the arguments for the top-level command, and for subcommands they are usually
|
|
378
|
+
You use `.arguments` to specify the expected command-arguments for the top-level command, and for subcommands they are usually
|
|
379
|
+
included in the `.command` call. Angled brackets (e.g. `<required>`) indicate required command-arguments.
|
|
380
|
+
Square brackets (e.g. `[optional]`) indicate optional command-arguments.
|
|
381
|
+
You can optionally describe the arguments in the help by supplying a hash as second parameter to `.description()`.
|
|
371
382
|
|
|
372
383
|
Example file: [env](./examples/env)
|
|
373
384
|
|
|
@@ -375,9 +386,13 @@ Example file: [env](./examples/env)
|
|
|
375
386
|
program
|
|
376
387
|
.version('0.1.0')
|
|
377
388
|
.arguments('<cmd> [env]')
|
|
389
|
+
.description('test command', {
|
|
390
|
+
cmd: 'command to run',
|
|
391
|
+
env: 'environment to run test in'
|
|
392
|
+
})
|
|
378
393
|
.action(function (cmd, env) {
|
|
379
|
-
console.log('command:',
|
|
380
|
-
console.log('environment:',
|
|
394
|
+
console.log('command:', cmd);
|
|
395
|
+
console.log('environment:', env || 'no environment given');
|
|
381
396
|
});
|
|
382
397
|
|
|
383
398
|
program.parse(process.argv);
|
package/index.js
CHANGED
|
@@ -838,7 +838,7 @@ Read more on https://git.io/JJc0W`);
|
|
|
838
838
|
_executeSubCommand(subcommand, args) {
|
|
839
839
|
args = args.slice();
|
|
840
840
|
let launchWithNode = false; // Use node for source targets so do not need to get permissions correct, and on Windows.
|
|
841
|
-
const sourceExt = ['.js', '.ts', '.mjs'];
|
|
841
|
+
const sourceExt = ['.js', '.ts', '.tsx', '.mjs'];
|
|
842
842
|
|
|
843
843
|
// Not checking for help first. Unlikely to have mandatory and executable, and can't robustly test for help flags in external command.
|
|
844
844
|
this._checkForMissingMandatoryOptions();
|
|
@@ -1576,7 +1576,6 @@ Read more on https://git.io/JJc0W`);
|
|
|
1576
1576
|
const columns = process.stdout.columns || 80;
|
|
1577
1577
|
const descriptionWidth = columns - width - 5;
|
|
1578
1578
|
desc.push('Arguments:');
|
|
1579
|
-
desc.push('');
|
|
1580
1579
|
this._args.forEach((arg) => {
|
|
1581
1580
|
desc.push(' ' + pad(arg.name, width) + ' ' + wrap(argsDescription[arg.name] || '', descriptionWidth, width + 4));
|
|
1582
1581
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "the complete solution for node.js command-line programs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"commander",
|
|
@@ -31,17 +31,20 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/jest": "^26.0.
|
|
35
|
-
"@types/node": "^14.
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
37
|
-
"eslint": "^
|
|
38
|
-
"eslint-config-standard-with-typescript": "^
|
|
39
|
-
"eslint-plugin-jest": "^
|
|
40
|
-
"jest": "^26.
|
|
41
|
-
"standard": "^
|
|
42
|
-
"typescript": "^
|
|
34
|
+
"@types/jest": "^26.0.15",
|
|
35
|
+
"@types/node": "^14.14.2",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^4.5.0",
|
|
37
|
+
"eslint": "^7.11.0",
|
|
38
|
+
"eslint-config-standard-with-typescript": "^19.0.1",
|
|
39
|
+
"eslint-plugin-jest": "^24.1.0",
|
|
40
|
+
"jest": "^26.6.0",
|
|
41
|
+
"standard": "^15.0.0",
|
|
42
|
+
"typescript": "^4.0.3"
|
|
43
43
|
},
|
|
44
44
|
"typings": "typings/index.d.ts",
|
|
45
|
+
"jest": {
|
|
46
|
+
"collectCoverage": true
|
|
47
|
+
},
|
|
45
48
|
"engines": {
|
|
46
49
|
"node": ">= 6"
|
|
47
50
|
}
|
package/typings/index.d.ts
CHANGED
|
@@ -109,6 +109,17 @@ declare namespace commander {
|
|
|
109
109
|
*/
|
|
110
110
|
arguments(desc: string): this;
|
|
111
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Override default decision whether to add implicit help command.
|
|
114
|
+
*
|
|
115
|
+
* addHelpCommand() // force on
|
|
116
|
+
* addHelpCommand(false); // force off
|
|
117
|
+
* addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
|
|
118
|
+
*
|
|
119
|
+
* @returns `this` command for chaining
|
|
120
|
+
*/
|
|
121
|
+
addHelpCommand(enableOrNameAndArgs?: string | boolean, description?: string): this;
|
|
122
|
+
|
|
112
123
|
/**
|
|
113
124
|
* Register callback to use as replacement for calling process.exit.
|
|
114
125
|
*/
|
|
@@ -394,6 +405,6 @@ declare namespace commander {
|
|
|
394
405
|
}
|
|
395
406
|
|
|
396
407
|
// Declaring namespace AND global
|
|
397
|
-
// eslint-disable-next-line no-redeclare
|
|
408
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare
|
|
398
409
|
declare const commander: commander.CommanderStatic;
|
|
399
410
|
export = commander;
|