commander 5.0.0 → 6.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/CHANGELOG.md +82 -109
- package/Readme.md +90 -51
- package/index.js +281 -111
- package/package.json +9 -9
- package/typings/index.d.ts +93 -62
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "the complete solution for node.js command-line programs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"commander",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/jest": "^
|
|
35
|
-
"@types/node": "^
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^2.
|
|
34
|
+
"@types/jest": "^26.0.5",
|
|
35
|
+
"@types/node": "^14.0.23",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^2.34.0",
|
|
37
37
|
"eslint": "^6.8.0",
|
|
38
|
-
"eslint-config-standard-with-typescript": "^
|
|
39
|
-
"eslint-plugin-jest": "^23.
|
|
40
|
-
"jest": "^
|
|
41
|
-
"standard": "^14.3.
|
|
42
|
-
"typescript": "^3.7
|
|
38
|
+
"eslint-config-standard-with-typescript": "^16.0.0",
|
|
39
|
+
"eslint-plugin-jest": "^23.18.0",
|
|
40
|
+
"jest": "^26.1.0",
|
|
41
|
+
"standard": "^14.3.4",
|
|
42
|
+
"typescript": "^3.9.7"
|
|
43
43
|
},
|
|
44
44
|
"typings": "typings/index.d.ts",
|
|
45
45
|
"engines": {
|
package/typings/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare namespace commander {
|
|
|
9
9
|
message: string;
|
|
10
10
|
nestedError?: string;
|
|
11
11
|
}
|
|
12
|
-
type CommanderErrorConstructor =
|
|
12
|
+
type CommanderErrorConstructor = new (exitCode: number, code: string, message: string) => CommanderError;
|
|
13
13
|
|
|
14
14
|
interface Option {
|
|
15
15
|
flags: string;
|
|
@@ -21,7 +21,7 @@ declare namespace commander {
|
|
|
21
21
|
long: string;
|
|
22
22
|
description: string;
|
|
23
23
|
}
|
|
24
|
-
type OptionConstructor =
|
|
24
|
+
type OptionConstructor = new (flags: string, description?: string) => Option;
|
|
25
25
|
|
|
26
26
|
interface ParseOptions {
|
|
27
27
|
from: 'node' | 'electron' | 'user';
|
|
@@ -35,21 +35,21 @@ declare namespace commander {
|
|
|
35
35
|
commands: Command[];
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* Set the program version to `str`.
|
|
38
|
+
* Set the program version to `str`.
|
|
39
39
|
*
|
|
40
40
|
* This method auto-registers the "-V, --version" flag
|
|
41
41
|
* which will print the version number when passed.
|
|
42
|
-
*
|
|
42
|
+
*
|
|
43
43
|
* You can optionally supply the flags and description to override the defaults.
|
|
44
44
|
*/
|
|
45
45
|
version(str: string, flags?: string, description?: string): this;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* Define a command, implemented using an action handler.
|
|
49
|
-
*
|
|
49
|
+
*
|
|
50
50
|
* @remarks
|
|
51
51
|
* The command description is supplied using `.description`, not as a parameter to `.command`.
|
|
52
|
-
*
|
|
52
|
+
*
|
|
53
53
|
* @example
|
|
54
54
|
* ```ts
|
|
55
55
|
* program
|
|
@@ -59,7 +59,7 @@ declare namespace commander {
|
|
|
59
59
|
* console.log('clone command called');
|
|
60
60
|
* });
|
|
61
61
|
* ```
|
|
62
|
-
*
|
|
62
|
+
*
|
|
63
63
|
* @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
64
64
|
* @param opts - configuration options
|
|
65
65
|
* @returns new command
|
|
@@ -67,23 +67,23 @@ declare namespace commander {
|
|
|
67
67
|
command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>;
|
|
68
68
|
/**
|
|
69
69
|
* Define a command, implemented in a separate executable file.
|
|
70
|
-
*
|
|
70
|
+
*
|
|
71
71
|
* @remarks
|
|
72
72
|
* The command description is supplied as the second parameter to `.command`.
|
|
73
|
-
*
|
|
73
|
+
*
|
|
74
74
|
* @example
|
|
75
75
|
* ```ts
|
|
76
76
|
* program
|
|
77
77
|
* .command('start <service>', 'start named service')
|
|
78
|
-
* .command('stop [service]', 'stop named
|
|
78
|
+
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
|
79
79
|
* ```
|
|
80
|
-
*
|
|
80
|
+
*
|
|
81
81
|
* @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
82
82
|
* @param description - description of executable command
|
|
83
83
|
* @param opts - configuration options
|
|
84
|
-
* @returns
|
|
84
|
+
* @returns `this` command for chaining
|
|
85
85
|
*/
|
|
86
|
-
command(nameAndArgs: string, description: string, opts?: commander.
|
|
86
|
+
command(nameAndArgs: string, description: string, opts?: commander.ExecutableCommandOptions): this;
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
89
|
* Factory routine to create a new unattached command.
|
|
@@ -92,20 +92,20 @@ declare namespace commander {
|
|
|
92
92
|
* create the command. You can override createCommand to customise subcommands.
|
|
93
93
|
*/
|
|
94
94
|
createCommand(name?: string): Command;
|
|
95
|
-
|
|
95
|
+
|
|
96
96
|
/**
|
|
97
97
|
* Add a prepared subcommand.
|
|
98
|
-
*
|
|
98
|
+
*
|
|
99
99
|
* See .command() for creating an attached subcommand which inherits settings from its parent.
|
|
100
|
-
*
|
|
101
|
-
* @returns
|
|
100
|
+
*
|
|
101
|
+
* @returns `this` command for chaining
|
|
102
102
|
*/
|
|
103
|
-
addCommand(cmd: Command): this;
|
|
103
|
+
addCommand(cmd: Command, opts?: CommandOptions): this;
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
* Define argument syntax for
|
|
106
|
+
* Define argument syntax for command.
|
|
107
107
|
*
|
|
108
|
-
* @returns
|
|
108
|
+
* @returns `this` command for chaining
|
|
109
109
|
*/
|
|
110
110
|
arguments(desc: string): this;
|
|
111
111
|
|
|
@@ -125,7 +125,7 @@ declare namespace commander {
|
|
|
125
125
|
* // output help here
|
|
126
126
|
* });
|
|
127
127
|
*
|
|
128
|
-
* @returns
|
|
128
|
+
* @returns `this` command for chaining
|
|
129
129
|
*/
|
|
130
130
|
action(fn: (...args: any[]) => void | Promise<void>): this;
|
|
131
131
|
|
|
@@ -169,7 +169,7 @@ declare namespace commander {
|
|
|
169
169
|
* // optional argument
|
|
170
170
|
* program.option('-c, --cheese [type]', 'add cheese [marble]');
|
|
171
171
|
*
|
|
172
|
-
* @returns
|
|
172
|
+
* @returns `this` command for chaining
|
|
173
173
|
*/
|
|
174
174
|
option(flags: string, description?: string, defaultValue?: string | boolean): this;
|
|
175
175
|
option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
|
|
@@ -185,34 +185,45 @@ declare namespace commander {
|
|
|
185
185
|
requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
|
|
186
186
|
requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
|
|
187
187
|
|
|
188
|
-
|
|
189
188
|
/**
|
|
190
189
|
* Whether to store option values as properties on command object,
|
|
191
190
|
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
|
192
191
|
*
|
|
193
|
-
* @
|
|
192
|
+
* @returns `this` command for chaining
|
|
194
193
|
*/
|
|
195
194
|
storeOptionsAsProperties(value?: boolean): this;
|
|
196
195
|
|
|
197
196
|
/**
|
|
198
197
|
* Whether to pass command to action handler,
|
|
199
198
|
* or just the options (specify false).
|
|
200
|
-
*
|
|
201
|
-
* @
|
|
199
|
+
*
|
|
200
|
+
* @returns `this` command for chaining
|
|
202
201
|
*/
|
|
203
202
|
passCommandToAction(value?: boolean): this;
|
|
204
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Alter parsing of short flags with optional values.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* // for `.option('-f,--flag [value]'):
|
|
209
|
+
* .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
210
|
+
* .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
211
|
+
*
|
|
212
|
+
* @returns `this` command for chaining
|
|
213
|
+
*/
|
|
214
|
+
combineFlagAndOptionalValue(arg?: boolean): this;
|
|
215
|
+
|
|
205
216
|
/**
|
|
206
217
|
* Allow unknown options on the command line.
|
|
207
218
|
*
|
|
208
219
|
* @param [arg] if `true` or omitted, no error will be thrown for unknown options.
|
|
209
|
-
* @returns
|
|
220
|
+
* @returns `this` command for chaining
|
|
210
221
|
*/
|
|
211
222
|
allowUnknownOption(arg?: boolean): this;
|
|
212
223
|
|
|
213
224
|
/**
|
|
214
225
|
* Parse `argv`, setting options and invoking commands when defined.
|
|
215
|
-
*
|
|
226
|
+
*
|
|
216
227
|
* The default expectation is that the arguments are from node and have the application as argv[0]
|
|
217
228
|
* and the script being run in argv[1], with user parameters after that.
|
|
218
229
|
*
|
|
@@ -221,16 +232,16 @@ declare namespace commander {
|
|
|
221
232
|
* program.parse(process.argv);
|
|
222
233
|
* program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
|
|
223
234
|
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
224
|
-
*
|
|
225
|
-
* @returns
|
|
235
|
+
*
|
|
236
|
+
* @returns `this` command for chaining
|
|
226
237
|
*/
|
|
227
238
|
parse(argv?: string[], options?: ParseOptions): this;
|
|
228
239
|
|
|
229
240
|
/**
|
|
230
241
|
* Parse `argv`, setting options and invoking commands when defined.
|
|
231
|
-
*
|
|
242
|
+
*
|
|
232
243
|
* Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
|
|
233
|
-
*
|
|
244
|
+
*
|
|
234
245
|
* The default expectation is that the arguments are from node and have the application as argv[0]
|
|
235
246
|
* and the script being run in argv[1], with user parameters after that.
|
|
236
247
|
*
|
|
@@ -264,8 +275,8 @@ declare namespace commander {
|
|
|
264
275
|
|
|
265
276
|
/**
|
|
266
277
|
* Set the description.
|
|
267
|
-
*
|
|
268
|
-
* @returns
|
|
278
|
+
*
|
|
279
|
+
* @returns `this` command for chaining
|
|
269
280
|
*/
|
|
270
281
|
description(str: string, argsDescription?: {[argName: string]: string}): this;
|
|
271
282
|
/**
|
|
@@ -275,8 +286,10 @@ declare namespace commander {
|
|
|
275
286
|
|
|
276
287
|
/**
|
|
277
288
|
* Set an alias for the command.
|
|
278
|
-
*
|
|
279
|
-
*
|
|
289
|
+
*
|
|
290
|
+
* You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
|
|
291
|
+
*
|
|
292
|
+
* @returns `this` command for chaining
|
|
280
293
|
*/
|
|
281
294
|
alias(alias: string): this;
|
|
282
295
|
/**
|
|
@@ -284,10 +297,23 @@ declare namespace commander {
|
|
|
284
297
|
*/
|
|
285
298
|
alias(): string;
|
|
286
299
|
|
|
300
|
+
/**
|
|
301
|
+
* Set aliases for the command.
|
|
302
|
+
*
|
|
303
|
+
* Only the first alias is shown in the auto-generated help.
|
|
304
|
+
*
|
|
305
|
+
* @returns `this` command for chaining
|
|
306
|
+
*/
|
|
307
|
+
aliases(aliases: string[]): this;
|
|
308
|
+
/**
|
|
309
|
+
* Get aliases for the command.
|
|
310
|
+
*/
|
|
311
|
+
aliases(): string[];
|
|
312
|
+
|
|
287
313
|
/**
|
|
288
314
|
* Set the command usage.
|
|
289
|
-
*
|
|
290
|
-
* @returns
|
|
315
|
+
*
|
|
316
|
+
* @returns `this` command for chaining
|
|
291
317
|
*/
|
|
292
318
|
usage(str: string): this;
|
|
293
319
|
/**
|
|
@@ -297,8 +323,8 @@ declare namespace commander {
|
|
|
297
323
|
|
|
298
324
|
/**
|
|
299
325
|
* Set the name of the command.
|
|
300
|
-
*
|
|
301
|
-
* @returns
|
|
326
|
+
*
|
|
327
|
+
* @returns `this` command for chaining
|
|
302
328
|
*/
|
|
303
329
|
name(str: string): this;
|
|
304
330
|
/**
|
|
@@ -318,21 +344,22 @@ declare namespace commander {
|
|
|
318
344
|
* Return command help documentation.
|
|
319
345
|
*/
|
|
320
346
|
helpInformation(): string;
|
|
321
|
-
|
|
347
|
+
|
|
322
348
|
/**
|
|
323
349
|
* You can pass in flags and a description to override the help
|
|
324
|
-
* flags and help description for your command.
|
|
350
|
+
* flags and help description for your command. Pass in false
|
|
351
|
+
* to disable the built-in help option.
|
|
325
352
|
*/
|
|
326
|
-
helpOption(flags?: string, description?: string): this;
|
|
353
|
+
helpOption(flags?: string | boolean, description?: string): this;
|
|
327
354
|
|
|
328
|
-
/**
|
|
355
|
+
/**
|
|
329
356
|
* Output help information and exit.
|
|
330
357
|
*/
|
|
331
358
|
help(cb?: (str: string) => string): never;
|
|
332
359
|
|
|
333
360
|
/**
|
|
334
361
|
* Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
|
|
335
|
-
*
|
|
362
|
+
*
|
|
336
363
|
* @example
|
|
337
364
|
* program
|
|
338
365
|
* .on('--help', () -> {
|
|
@@ -341,28 +368,32 @@ declare namespace commander {
|
|
|
341
368
|
*/
|
|
342
369
|
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
|
343
370
|
}
|
|
344
|
-
type CommandConstructor =
|
|
371
|
+
type CommandConstructor = new (name?: string) => Command;
|
|
345
372
|
|
|
373
|
+
interface CommandOptions {
|
|
374
|
+
noHelp?: boolean; // old name for hidden
|
|
375
|
+
hidden?: boolean;
|
|
376
|
+
isDefault?: boolean;
|
|
377
|
+
}
|
|
378
|
+
interface ExecutableCommandOptions extends CommandOptions {
|
|
379
|
+
executableFile?: string;
|
|
380
|
+
}
|
|
346
381
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
interface ParseOptionsResult {
|
|
354
|
-
operands: string[];
|
|
355
|
-
unknown: string[];
|
|
356
|
-
}
|
|
382
|
+
interface ParseOptionsResult {
|
|
383
|
+
operands: string[];
|
|
384
|
+
unknown: string[];
|
|
385
|
+
}
|
|
357
386
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
387
|
+
interface CommanderStatic extends Command {
|
|
388
|
+
program: Command;
|
|
389
|
+
Command: CommandConstructor;
|
|
390
|
+
Option: OptionConstructor;
|
|
391
|
+
CommanderError: CommanderErrorConstructor;
|
|
392
|
+
}
|
|
364
393
|
|
|
365
394
|
}
|
|
366
395
|
|
|
396
|
+
// Declaring namespace AND global
|
|
397
|
+
// eslint-disable-next-line no-redeclare
|
|
367
398
|
declare const commander: commander.CommanderStatic;
|
|
368
399
|
export = commander;
|