lerna-projen 0.1.38 → 0.1.40

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.
@@ -1,410 +1,890 @@
1
1
  // Type definitions for commander
2
2
  // Original definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>, Jules Randolph <https://github.com/sveinburne>
3
3
 
4
- declare namespace commander {
5
-
6
- interface CommanderError extends Error {
7
- code: string;
8
- exitCode: number;
9
- message: string;
10
- nestedError?: string;
11
- }
12
- type CommanderErrorConstructor = new (exitCode: number, code: string, message: string) => CommanderError;
13
-
14
- interface Option {
15
- flags: string;
16
- required: boolean; // A value must be supplied when the option is specified.
17
- optional: boolean; // A value is optional when the option is specified.
18
- mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line.
19
- bool: boolean;
20
- short?: string;
21
- long: string;
22
- description: string;
23
- }
24
- type OptionConstructor = new (flags: string, description?: string) => Option;
25
-
26
- interface ParseOptions {
27
- from: 'node' | 'electron' | 'user';
28
- }
29
-
30
- interface Command {
31
- [key: string]: any; // options as properties
32
-
33
- args: string[];
34
-
35
- commands: Command[];
36
-
37
- /**
38
- * Set the program version to `str`.
39
- *
40
- * This method auto-registers the "-V, --version" flag
41
- * which will print the version number when passed.
42
- *
43
- * You can optionally supply the flags and description to override the defaults.
44
- */
45
- version(str: string, flags?: string, description?: string): this;
46
-
47
- /**
48
- * Define a command, implemented using an action handler.
49
- *
50
- * @remarks
51
- * The command description is supplied using `.description`, not as a parameter to `.command`.
52
- *
53
- * @example
54
- * ```ts
55
- * program
56
- * .command('clone <source> [destination]')
57
- * .description('clone a repository into a newly created directory')
58
- * .action((source, destination) => {
59
- * console.log('clone command called');
60
- * });
61
- * ```
62
- *
63
- * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
64
- * @param opts - configuration options
65
- * @returns new command
66
- */
67
- command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>;
68
- /**
69
- * Define a command, implemented in a separate executable file.
70
- *
71
- * @remarks
72
- * The command description is supplied as the second parameter to `.command`.
73
- *
74
- * @example
75
- * ```ts
76
- * program
77
- * .command('start <service>', 'start named service')
78
- * .command('stop [service]', 'stop named service, or all if no name supplied');
79
- * ```
80
- *
81
- * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
82
- * @param description - description of executable command
83
- * @param opts - configuration options
84
- * @returns `this` command for chaining
85
- */
86
- command(nameAndArgs: string, description: string, opts?: commander.ExecutableCommandOptions): this;
87
-
88
- /**
89
- * Factory routine to create a new unattached command.
90
- *
91
- * See .command() for creating an attached subcommand, which uses this routine to
92
- * create the command. You can override createCommand to customise subcommands.
93
- */
94
- createCommand(name?: string): Command;
95
-
96
- /**
97
- * Add a prepared subcommand.
98
- *
99
- * See .command() for creating an attached subcommand which inherits settings from its parent.
100
- *
101
- * @returns `this` command for chaining
102
- */
103
- addCommand(cmd: Command, opts?: CommandOptions): this;
104
-
105
- /**
106
- * Define argument syntax for command.
107
- *
108
- * @returns `this` command for chaining
109
- */
110
- arguments(desc: string): this;
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
-
123
- /**
124
- * Register callback to use as replacement for calling process.exit.
125
- */
126
- exitOverride(callback?: (err: CommanderError) => never|void): this;
127
-
128
- /**
129
- * Register callback `fn` for the command.
130
- *
131
- * @example
132
- * program
133
- * .command('help')
134
- * .description('display verbose help')
135
- * .action(function() {
136
- * // output help here
137
- * });
138
- *
139
- * @returns `this` command for chaining
140
- */
141
- action(fn: (...args: any[]) => void | Promise<void>): this;
142
-
143
- /**
144
- * Define option with `flags`, `description` and optional
145
- * coercion `fn`.
146
- *
147
- * The `flags` string should contain both the short and long flags,
148
- * separated by comma, a pipe or space. The following are all valid
149
- * all will output this way when `--help` is used.
150
- *
151
- * "-p, --pepper"
152
- * "-p|--pepper"
153
- * "-p --pepper"
154
- *
155
- * @example
156
- * // simple boolean defaulting to false
157
- * program.option('-p, --pepper', 'add pepper');
158
- *
159
- * --pepper
160
- * program.pepper
161
- * // => Boolean
162
- *
163
- * // simple boolean defaulting to true
164
- * program.option('-C, --no-cheese', 'remove cheese');
165
- *
166
- * program.cheese
167
- * // => true
168
- *
169
- * --no-cheese
170
- * program.cheese
171
- * // => false
172
- *
173
- * // required argument
174
- * program.option('-C, --chdir <path>', 'change the working directory');
175
- *
176
- * --chdir /tmp
177
- * program.chdir
178
- * // => "/tmp"
179
- *
180
- * // optional argument
181
- * program.option('-c, --cheese [type]', 'add cheese [marble]');
182
- *
183
- * @returns `this` command for chaining
184
- */
185
- option(flags: string, description?: string, defaultValue?: string | boolean): this;
186
- option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
187
- option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
188
-
189
- /**
190
- * Define a required option, which must have a value after parsing. This usually means
191
- * the option must be specified on the command line. (Otherwise the same as .option().)
192
- *
193
- * The `flags` string should contain both the short and long flags, separated by comma, a pipe or space.
194
- */
195
- requiredOption(flags: string, description?: string, defaultValue?: string | boolean): this;
196
- requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
197
- requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
198
-
199
- /**
200
- * Whether to store option values as properties on command object,
201
- * or store separately (specify false). In both cases the option values can be accessed using .opts().
202
- *
203
- * @returns `this` command for chaining
204
- */
205
- storeOptionsAsProperties(value?: boolean): this;
206
-
207
- /**
208
- * Whether to pass command to action handler,
209
- * or just the options (specify false).
210
- *
211
- * @returns `this` command for chaining
212
- */
213
- passCommandToAction(value?: boolean): this;
214
-
215
- /**
216
- * Alter parsing of short flags with optional values.
217
- *
218
- * @example
219
- * // for `.option('-f,--flag [value]'):
220
- * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
221
- * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
222
- *
223
- * @returns `this` command for chaining
224
- */
225
- combineFlagAndOptionalValue(arg?: boolean): this;
226
-
227
- /**
228
- * Allow unknown options on the command line.
229
- *
230
- * @param [arg] if `true` or omitted, no error will be thrown for unknown options.
231
- * @returns `this` command for chaining
232
- */
233
- allowUnknownOption(arg?: boolean): this;
234
-
235
- /**
236
- * Parse `argv`, setting options and invoking commands when defined.
237
- *
238
- * The default expectation is that the arguments are from node and have the application as argv[0]
239
- * and the script being run in argv[1], with user parameters after that.
240
- *
241
- * Examples:
242
- *
243
- * program.parse(process.argv);
244
- * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
245
- * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
246
- *
247
- * @returns `this` command for chaining
248
- */
249
- parse(argv?: string[], options?: ParseOptions): this;
250
-
251
- /**
252
- * Parse `argv`, setting options and invoking commands when defined.
253
- *
254
- * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
255
- *
256
- * The default expectation is that the arguments are from node and have the application as argv[0]
257
- * and the script being run in argv[1], with user parameters after that.
258
- *
259
- * Examples:
260
- *
261
- * program.parseAsync(process.argv);
262
- * program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
263
- * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
264
- *
265
- * @returns Promise
266
- */
267
- parseAsync(argv?: string[], options?: ParseOptions): Promise<this>;
268
-
269
- /**
270
- * Parse options from `argv` removing known options,
271
- * and return argv split into operands and unknown arguments.
272
- *
273
- * @example
274
- * argv => operands, unknown
275
- * --known kkk op => [op], []
276
- * op --known kkk => [op], []
277
- * sub --unknown uuu op => [sub], [--unknown uuu op]
278
- * sub -- --unknown uuu op => [sub --unknown uuu op], []
279
- */
280
- parseOptions(argv: string[]): commander.ParseOptionsResult;
281
-
282
- /**
283
- * Return an object containing options as key-value pairs
284
- */
285
- opts(): { [key: string]: any };
286
-
287
- /**
288
- * Set the description.
289
- *
290
- * @returns `this` command for chaining
291
- */
292
- description(str: string, argsDescription?: {[argName: string]: string}): this;
293
- /**
294
- * Get the description.
295
- */
296
- description(): string;
297
-
298
- /**
299
- * Set an alias for the command.
300
- *
301
- * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
302
- *
303
- * @returns `this` command for chaining
304
- */
305
- alias(alias: string): this;
306
- /**
307
- * Get alias for the command.
308
- */
309
- alias(): string;
310
-
311
- /**
312
- * Set aliases for the command.
313
- *
314
- * Only the first alias is shown in the auto-generated help.
315
- *
316
- * @returns `this` command for chaining
317
- */
318
- aliases(aliases: string[]): this;
319
- /**
320
- * Get aliases for the command.
321
- */
322
- aliases(): string[];
323
-
324
- /**
325
- * Set the command usage.
326
- *
327
- * @returns `this` command for chaining
328
- */
329
- usage(str: string): this;
330
- /**
331
- * Get the command usage.
332
- */
333
- usage(): string;
334
-
335
- /**
336
- * Set the name of the command.
337
- *
338
- * @returns `this` command for chaining
339
- */
340
- name(str: string): this;
341
- /**
342
- * Get the name of the command.
343
- */
344
- name(): string;
345
-
346
- /**
347
- * Output help information for this command.
348
- *
349
- * When listener(s) are available for the helpLongFlag
350
- * those callbacks are invoked.
351
- */
352
- outputHelp(cb?: (str: string) => string): void;
353
-
354
- /**
355
- * Return command help documentation.
356
- */
357
- helpInformation(): string;
358
-
359
- /**
360
- * You can pass in flags and a description to override the help
361
- * flags and help description for your command. Pass in false
362
- * to disable the built-in help option.
363
- */
364
- helpOption(flags?: string | boolean, description?: string): this;
365
-
366
- /**
367
- * Output help information and exit.
368
- */
369
- help(cb?: (str: string) => string): never;
370
-
371
- /**
372
- * Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
373
- *
374
- * @example
375
- * program
376
- * .on('--help', () -> {
377
- * console.log('See web site for more information.');
378
- * });
379
- */
380
- on(event: string | symbol, listener: (...args: any[]) => void): this;
381
- }
382
- type CommandConstructor = new (name?: string) => Command;
383
-
384
- interface CommandOptions {
385
- noHelp?: boolean; // old name for hidden
386
- hidden?: boolean;
387
- isDefault?: boolean;
388
- }
389
- interface ExecutableCommandOptions extends CommandOptions {
390
- executableFile?: string;
391
- }
392
-
393
- interface ParseOptionsResult {
394
- operands: string[];
395
- unknown: string[];
396
- }
397
-
398
- interface CommanderStatic extends Command {
399
- program: Command;
400
- Command: CommandConstructor;
401
- Option: OptionConstructor;
402
- CommanderError: CommanderErrorConstructor;
403
- }
4
+ // Using method rather than property for method-signature-style, to document method overloads separately. Allow either.
5
+ /* eslint-disable @typescript-eslint/method-signature-style */
6
+ /* eslint-disable @typescript-eslint/no-explicit-any */
7
+
8
+ export class CommanderError extends Error {
9
+ code: string;
10
+ exitCode: number;
11
+ message: string;
12
+ nestedError?: string;
13
+
14
+ /**
15
+ * Constructs the CommanderError class
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
+ * @constructor
20
+ */
21
+ constructor(exitCode: number, code: string, message: string);
22
+ }
23
+
24
+ export class InvalidArgumentError extends CommanderError {
25
+ /**
26
+ * Constructs the InvalidArgumentError class
27
+ * @param message - explanation of why argument is invalid
28
+ * @constructor
29
+ */
30
+ constructor(message: string);
31
+ }
32
+ export { InvalidArgumentError as InvalidOptionArgumentError }; // deprecated old name
33
+
34
+ export interface ErrorOptions { // optional parameter for error()
35
+ /** an id string representing the error */
36
+ code?: string;
37
+ /** suggested exit code which could be used with process.exit */
38
+ exitCode?: number;
39
+ }
40
+
41
+ export class Argument {
42
+ description: string;
43
+ required: boolean;
44
+ variadic: boolean;
45
+
46
+ /**
47
+ * Initialize a new command argument with the given name and description.
48
+ * The default is that the argument is required, and you can explicitly
49
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
50
+ */
51
+ constructor(arg: string, description?: string);
52
+
53
+ /**
54
+ * Return argument name.
55
+ */
56
+ name(): string;
57
+
58
+ /**
59
+ * Set the default value, and optionally supply the description to be displayed in the help.
60
+ */
61
+ default(value: unknown, description?: string): this;
62
+
63
+ /**
64
+ * Set the custom handler for processing CLI command arguments into argument values.
65
+ */
66
+ argParser<T>(fn: (value: string, previous: T) => T): this;
67
+
68
+ /**
69
+ * Only allow argument value to be one of choices.
70
+ */
71
+ choices(values: readonly string[]): this;
72
+
73
+ /**
74
+ * Make argument required.
75
+ */
76
+ argRequired(): this;
77
+
78
+ /**
79
+ * Make argument optional.
80
+ */
81
+ argOptional(): this;
82
+ }
83
+
84
+ export class Option {
85
+ flags: string;
86
+ description: string;
87
+
88
+ required: boolean; // A value must be supplied when the option is specified.
89
+ optional: boolean; // A value is optional when the option is specified.
90
+ variadic: boolean;
91
+ mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line.
92
+ optionFlags: string;
93
+ short?: string;
94
+ long?: string;
95
+ negate: boolean;
96
+ defaultValue?: any;
97
+ defaultValueDescription?: string;
98
+ parseArg?: <T>(value: string, previous: T) => T;
99
+ hidden: boolean;
100
+ argChoices?: string[];
101
+
102
+ constructor(flags: string, description?: string);
103
+
104
+ /**
105
+ * Set the default value, and optionally supply the description to be displayed in the help.
106
+ */
107
+ default(value: unknown, description?: string): this;
108
+
109
+ /**
110
+ * Preset to use when option used without option-argument, especially optional but also boolean and negated.
111
+ * The custom processing (parseArg) is called.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * new Option('--color').default('GREYSCALE').preset('RGB');
116
+ * new Option('--donate [amount]').preset('20').argParser(parseFloat);
117
+ * ```
118
+ */
119
+ preset(arg: unknown): this;
120
+
121
+ /**
122
+ * Add option name(s) that conflict with this option.
123
+ * An error will be displayed if conflicting options are found during parsing.
124
+ *
125
+ * @example
126
+ * ```ts
127
+ * new Option('--rgb').conflicts('cmyk');
128
+ * new Option('--js').conflicts(['ts', 'jsx']);
129
+ * ```
130
+ */
131
+ conflicts(names: string | string[]): this;
132
+
133
+ /**
134
+ * Specify implied option values for when this option is set and the implied options are not.
135
+ *
136
+ * The custom processing (parseArg) is not called on the implied values.
137
+ *
138
+ * @example
139
+ * program
140
+ * .addOption(new Option('--log', 'write logging information to file'))
141
+ * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
142
+ */
143
+ implies(optionValues: OptionValues): this;
144
+
145
+ /**
146
+ * Set environment variable to check for option value.
147
+ *
148
+ * An environment variables is only used if when processed the current option value is
149
+ * undefined, or the source of the current value is 'default' or 'config' or 'env'.
150
+ */
151
+ env(name: string): this;
152
+
153
+ /**
154
+ * Calculate the full description, including defaultValue etc.
155
+ */
156
+ fullDescription(): string;
157
+
158
+ /**
159
+ * Set the custom handler for processing CLI option arguments into option values.
160
+ */
161
+ argParser<T>(fn: (value: string, previous: T) => T): this;
162
+
163
+ /**
164
+ * Whether the option is mandatory and must have a value after parsing.
165
+ */
166
+ makeOptionMandatory(mandatory?: boolean): this;
167
+
168
+ /**
169
+ * Hide option in help.
170
+ */
171
+ hideHelp(hide?: boolean): this;
172
+
173
+ /**
174
+ * Only allow option value to be one of choices.
175
+ */
176
+ choices(values: readonly string[]): this;
177
+
178
+ /**
179
+ * Return option name.
180
+ */
181
+ name(): string;
182
+
183
+ /**
184
+ * Return option name, in a camelcase format that can be used
185
+ * as a object attribute key.
186
+ */
187
+ attributeName(): string;
188
+
189
+ /**
190
+ * Return whether a boolean option.
191
+ *
192
+ * Options are one of boolean, negated, required argument, or optional argument.
193
+ */
194
+ isBoolean(): boolean;
195
+ }
404
196
 
197
+ export class Help {
198
+ /** output helpWidth, long lines are wrapped to fit */
199
+ helpWidth?: number;
200
+ sortSubcommands: boolean;
201
+ sortOptions: boolean;
202
+ showGlobalOptions: boolean;
203
+
204
+ constructor();
205
+
206
+ /** Get the command term to show in the list of subcommands. */
207
+ subcommandTerm(cmd: Command): string;
208
+ /** Get the command summary to show in the list of subcommands. */
209
+ subcommandDescription(cmd: Command): string;
210
+ /** Get the option term to show in the list of options. */
211
+ optionTerm(option: Option): string;
212
+ /** Get the option description to show in the list of options. */
213
+ optionDescription(option: Option): string;
214
+ /** Get the argument term to show in the list of arguments. */
215
+ argumentTerm(argument: Argument): string;
216
+ /** Get the argument description to show in the list of arguments. */
217
+ argumentDescription(argument: Argument): string;
218
+
219
+ /** Get the command usage to be displayed at the top of the built-in help. */
220
+ commandUsage(cmd: Command): string;
221
+ /** Get the description for the command. */
222
+ commandDescription(cmd: Command): string;
223
+
224
+ /** Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one. */
225
+ visibleCommands(cmd: Command): Command[];
226
+ /** Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one. */
227
+ visibleOptions(cmd: Command): Option[];
228
+ /** Get an array of the visible global options. (Not including help.) */
229
+ visibleGlobalOptions(cmd: Command): Option[];
230
+ /** Get an array of the arguments which have descriptions. */
231
+ visibleArguments(cmd: Command): Argument[];
232
+
233
+ /** Get the longest command term length. */
234
+ longestSubcommandTermLength(cmd: Command, helper: Help): number;
235
+ /** Get the longest option term length. */
236
+ longestOptionTermLength(cmd: Command, helper: Help): number;
237
+ /** Get the longest global option term length. */
238
+ longestGlobalOptionTermLength(cmd: Command, helper: Help): number;
239
+ /** Get the longest argument term length. */
240
+ longestArgumentTermLength(cmd: Command, helper: Help): number;
241
+ /** Calculate the pad width from the maximum term length. */
242
+ padWidth(cmd: Command, helper: Help): number;
243
+
244
+ /**
245
+ * Wrap the given string to width characters per line, with lines after the first indented.
246
+ * Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
247
+ */
248
+ wrap(str: string, width: number, indent: number, minColumnWidth?: number): string;
249
+
250
+ /** Generate the built-in help text. */
251
+ formatHelp(cmd: Command, helper: Help): string;
252
+ }
253
+ export type HelpConfiguration = Partial<Help>;
254
+
255
+ export interface ParseOptions {
256
+ from: 'node' | 'electron' | 'user';
257
+ }
258
+ export interface HelpContext { // optional parameter for .help() and .outputHelp()
259
+ error: boolean;
405
260
  }
261
+ export interface AddHelpTextContext { // passed to text function used with .addHelpText()
262
+ error: boolean;
263
+ command: Command;
264
+ }
265
+ export interface OutputConfiguration {
266
+ writeOut?(str: string): void;
267
+ writeErr?(str: string): void;
268
+ getOutHelpWidth?(): number;
269
+ getErrHelpWidth?(): number;
270
+ outputError?(str: string, write: (str: string) => void): void;
271
+
272
+ }
273
+
274
+ export type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';
275
+ export type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';
276
+ export type OptionValueSource = 'default' | 'config' | 'env' | 'cli' | 'implied';
277
+
278
+ export type OptionValues = Record<string, any>;
279
+
280
+ export class Command {
281
+ args: string[];
282
+ processedArgs: any[];
283
+ readonly commands: readonly Command[];
284
+ readonly options: readonly Option[];
285
+ parent: Command | null;
286
+
287
+ constructor(name?: string);
288
+
289
+ /**
290
+ * Set the program version to `str`.
291
+ *
292
+ * This method auto-registers the "-V, --version" flag
293
+ * which will print the version number when passed.
294
+ *
295
+ * You can optionally supply the flags and description to override the defaults.
296
+ */
297
+ version(str: string, flags?: string, description?: string): this;
298
+
299
+ /**
300
+ * Define a command, implemented using an action handler.
301
+ *
302
+ * @remarks
303
+ * The command description is supplied using `.description`, not as a parameter to `.command`.
304
+ *
305
+ * @example
306
+ * ```ts
307
+ * program
308
+ * .command('clone <source> [destination]')
309
+ * .description('clone a repository into a newly created directory')
310
+ * .action((source, destination) => {
311
+ * console.log('clone command called');
312
+ * });
313
+ * ```
314
+ *
315
+ * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
316
+ * @param opts - configuration options
317
+ * @returns new command
318
+ */
319
+ command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>;
320
+ /**
321
+ * Define a command, implemented in a separate executable file.
322
+ *
323
+ * @remarks
324
+ * The command description is supplied as the second parameter to `.command`.
325
+ *
326
+ * @example
327
+ * ```ts
328
+ * program
329
+ * .command('start <service>', 'start named service')
330
+ * .command('stop [service]', 'stop named service, or all if no name supplied');
331
+ * ```
332
+ *
333
+ * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
334
+ * @param description - description of executable command
335
+ * @param opts - configuration options
336
+ * @returns `this` command for chaining
337
+ */
338
+ command(nameAndArgs: string, description: string, opts?: ExecutableCommandOptions): this;
339
+
340
+ /**
341
+ * Factory routine to create a new unattached command.
342
+ *
343
+ * See .command() for creating an attached subcommand, which uses this routine to
344
+ * create the command. You can override createCommand to customise subcommands.
345
+ */
346
+ createCommand(name?: string): Command;
347
+
348
+ /**
349
+ * Add a prepared subcommand.
350
+ *
351
+ * See .command() for creating an attached subcommand which inherits settings from its parent.
352
+ *
353
+ * @returns `this` command for chaining
354
+ */
355
+ addCommand(cmd: Command, opts?: CommandOptions): this;
356
+
357
+ /**
358
+ * Factory routine to create a new unattached argument.
359
+ *
360
+ * See .argument() for creating an attached argument, which uses this routine to
361
+ * create the argument. You can override createArgument to return a custom argument.
362
+ */
363
+ createArgument(name: string, description?: string): Argument;
364
+
365
+ /**
366
+ * Define argument syntax for command.
367
+ *
368
+ * The default is that the argument is required, and you can explicitly
369
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
370
+ *
371
+ * @example
372
+ * ```
373
+ * program.argument('<input-file>');
374
+ * program.argument('[output-file]');
375
+ * ```
376
+ *
377
+ * @returns `this` command for chaining
378
+ */
379
+ argument<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
380
+ argument(name: string, description?: string, defaultValue?: unknown): this;
381
+
382
+ /**
383
+ * Define argument syntax for command, adding a prepared argument.
384
+ *
385
+ * @returns `this` command for chaining
386
+ */
387
+ addArgument(arg: Argument): this;
388
+
389
+ /**
390
+ * Define argument syntax for command, adding multiple at once (without descriptions).
391
+ *
392
+ * See also .argument().
393
+ *
394
+ * @example
395
+ * ```
396
+ * program.arguments('<cmd> [env]');
397
+ * ```
398
+ *
399
+ * @returns `this` command for chaining
400
+ */
401
+ arguments(names: string): this;
402
+
403
+ /**
404
+ * Override default decision whether to add implicit help command.
405
+ *
406
+ * @example
407
+ * ```
408
+ * addHelpCommand() // force on
409
+ * addHelpCommand(false); // force off
410
+ * addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
411
+ * ```
412
+ *
413
+ * @returns `this` command for chaining
414
+ */
415
+ addHelpCommand(enableOrNameAndArgs?: string | boolean, description?: string): this;
416
+
417
+ /**
418
+ * Add hook for life cycle event.
419
+ */
420
+ hook(event: HookEvent, listener: (thisCommand: Command, actionCommand: Command) => void | Promise<void>): this;
421
+
422
+ /**
423
+ * Register callback to use as replacement for calling process.exit.
424
+ */
425
+ exitOverride(callback?: (err: CommanderError) => never | void): this;
426
+
427
+ /**
428
+ * Display error message and exit (or call exitOverride).
429
+ */
430
+ error(message: string, errorOptions?: ErrorOptions): never;
431
+
432
+ /**
433
+ * You can customise the help with a subclass of Help by overriding createHelp,
434
+ * or by overriding Help properties using configureHelp().
435
+ */
436
+ createHelp(): Help;
437
+
438
+ /**
439
+ * You can customise the help by overriding Help properties using configureHelp(),
440
+ * or with a subclass of Help by overriding createHelp().
441
+ */
442
+ configureHelp(configuration: HelpConfiguration): this;
443
+ /** Get configuration */
444
+ configureHelp(): HelpConfiguration;
445
+
446
+ /**
447
+ * The default output goes to stdout and stderr. You can customise this for special
448
+ * applications. You can also customise the display of errors by overriding outputError.
449
+ *
450
+ * The configuration properties are all functions:
451
+ * ```
452
+ * // functions to change where being written, stdout and stderr
453
+ * writeOut(str)
454
+ * writeErr(str)
455
+ * // matching functions to specify width for wrapping help
456
+ * getOutHelpWidth()
457
+ * getErrHelpWidth()
458
+ * // functions based on what is being written out
459
+ * outputError(str, write) // used for displaying errors, and not used for displaying help
460
+ * ```
461
+ */
462
+ configureOutput(configuration: OutputConfiguration): this;
463
+ /** Get configuration */
464
+ configureOutput(): OutputConfiguration;
465
+
466
+ /**
467
+ * Copy settings that are useful to have in common across root command and subcommands.
468
+ *
469
+ * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
470
+ */
471
+ copyInheritedSettings(sourceCommand: Command): this;
472
+
473
+ /**
474
+ * Display the help or a custom message after an error occurs.
475
+ */
476
+ showHelpAfterError(displayHelp?: boolean | string): this;
477
+
478
+ /**
479
+ * Display suggestion of similar commands for unknown commands, or options for unknown options.
480
+ */
481
+ showSuggestionAfterError(displaySuggestion?: boolean): this;
482
+
483
+ /**
484
+ * Register callback `fn` for the command.
485
+ *
486
+ * @example
487
+ * ```
488
+ * program
489
+ * .command('serve')
490
+ * .description('start service')
491
+ * .action(function() {
492
+ * // do work here
493
+ * });
494
+ * ```
495
+ *
496
+ * @returns `this` command for chaining
497
+ */
498
+ action(fn: (...args: any[]) => void | Promise<void>): this;
499
+
500
+ /**
501
+ * Define option with `flags`, `description` and optional
502
+ * coercion `fn`.
503
+ *
504
+ * The `flags` string contains the short and/or long flags,
505
+ * separated by comma, a pipe or space. The following are all valid
506
+ * all will output this way when `--help` is used.
507
+ *
508
+ * "-p, --pepper"
509
+ * "-p|--pepper"
510
+ * "-p --pepper"
511
+ *
512
+ * @example
513
+ * ```
514
+ * // simple boolean defaulting to false
515
+ * program.option('-p, --pepper', 'add pepper');
516
+ *
517
+ * --pepper
518
+ * program.pepper
519
+ * // => Boolean
520
+ *
521
+ * // simple boolean defaulting to true
522
+ * program.option('-C, --no-cheese', 'remove cheese');
523
+ *
524
+ * program.cheese
525
+ * // => true
526
+ *
527
+ * --no-cheese
528
+ * program.cheese
529
+ * // => false
530
+ *
531
+ * // required argument
532
+ * program.option('-C, --chdir <path>', 'change the working directory');
533
+ *
534
+ * --chdir /tmp
535
+ * program.chdir
536
+ * // => "/tmp"
537
+ *
538
+ * // optional argument
539
+ * program.option('-c, --cheese [type]', 'add cheese [marble]');
540
+ * ```
541
+ *
542
+ * @returns `this` command for chaining
543
+ */
544
+ option(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
545
+ option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
546
+ /** @deprecated since v7, instead use choices or a custom function */
547
+ option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;
548
+
549
+ /**
550
+ * Define a required option, which must have a value after parsing. This usually means
551
+ * the option must be specified on the command line. (Otherwise the same as .option().)
552
+ *
553
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
554
+ */
555
+ requiredOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
556
+ requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
557
+ /** @deprecated since v7, instead use choices or a custom function */
558
+ requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;
559
+
560
+ /**
561
+ * Factory routine to create a new unattached option.
562
+ *
563
+ * See .option() for creating an attached option, which uses this routine to
564
+ * create the option. You can override createOption to return a custom option.
565
+ */
566
+
567
+ createOption(flags: string, description?: string): Option;
568
+
569
+ /**
570
+ * Add a prepared Option.
571
+ *
572
+ * See .option() and .requiredOption() for creating and attaching an option in a single call.
573
+ */
574
+ addOption(option: Option): this;
575
+
576
+ /**
577
+ * Whether to store option values as properties on command object,
578
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
579
+ *
580
+ * @returns `this` command for chaining
581
+ */
582
+ storeOptionsAsProperties<T extends OptionValues>(): this & T;
583
+ storeOptionsAsProperties<T extends OptionValues>(storeAsProperties: true): this & T;
584
+ storeOptionsAsProperties(storeAsProperties?: boolean): this;
585
+
586
+ /**
587
+ * Retrieve option value.
588
+ */
589
+ getOptionValue(key: string): any;
590
+
591
+ /**
592
+ * Store option value.
593
+ */
594
+ setOptionValue(key: string, value: unknown): this;
595
+
596
+ /**
597
+ * Store option value and where the value came from.
598
+ */
599
+ setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this;
600
+
601
+ /**
602
+ * Get source of option value.
603
+ */
604
+ getOptionValueSource(key: string): OptionValueSource | undefined;
605
+
606
+ /**
607
+ * Get source of option value. See also .optsWithGlobals().
608
+ */
609
+ getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined;
610
+
611
+ /**
612
+ * Alter parsing of short flags with optional values.
613
+ *
614
+ * @example
615
+ * ```
616
+ * // for `.option('-f,--flag [value]'):
617
+ * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
618
+ * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
619
+ * ```
620
+ *
621
+ * @returns `this` command for chaining
622
+ */
623
+ combineFlagAndOptionalValue(combine?: boolean): this;
624
+
625
+ /**
626
+ * Allow unknown options on the command line.
627
+ *
628
+ * @returns `this` command for chaining
629
+ */
630
+ allowUnknownOption(allowUnknown?: boolean): this;
631
+
632
+ /**
633
+ * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
634
+ *
635
+ * @returns `this` command for chaining
636
+ */
637
+ allowExcessArguments(allowExcess?: boolean): this;
638
+
639
+ /**
640
+ * Enable positional options. Positional means global options are specified before subcommands which lets
641
+ * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
642
+ *
643
+ * The default behaviour is non-positional and global options may appear anywhere on the command line.
644
+ *
645
+ * @returns `this` command for chaining
646
+ */
647
+ enablePositionalOptions(positional?: boolean): this;
648
+
649
+ /**
650
+ * Pass through options that come after command-arguments rather than treat them as command-options,
651
+ * so actual command-options come before command-arguments. Turning this on for a subcommand requires
652
+ * positional options to have been enabled on the program (parent commands).
653
+ *
654
+ * The default behaviour is non-positional and options may appear before or after command-arguments.
655
+ *
656
+ * @returns `this` command for chaining
657
+ */
658
+ passThroughOptions(passThrough?: boolean): this;
659
+
660
+ /**
661
+ * Parse `argv`, setting options and invoking commands when defined.
662
+ *
663
+ * The default expectation is that the arguments are from node and have the application as argv[0]
664
+ * and the script being run in argv[1], with user parameters after that.
665
+ *
666
+ * @example
667
+ * ```
668
+ * program.parse(process.argv);
669
+ * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
670
+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
671
+ * ```
672
+ *
673
+ * @returns `this` command for chaining
674
+ */
675
+ parse(argv?: readonly string[], options?: ParseOptions): this;
676
+
677
+ /**
678
+ * Parse `argv`, setting options and invoking commands when defined.
679
+ *
680
+ * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
681
+ *
682
+ * The default expectation is that the arguments are from node and have the application as argv[0]
683
+ * and the script being run in argv[1], with user parameters after that.
684
+ *
685
+ * @example
686
+ * ```
687
+ * program.parseAsync(process.argv);
688
+ * program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
689
+ * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
690
+ * ```
691
+ *
692
+ * @returns Promise
693
+ */
694
+ parseAsync(argv?: readonly string[], options?: ParseOptions): Promise<this>;
695
+
696
+ /**
697
+ * Parse options from `argv` removing known options,
698
+ * and return argv split into operands and unknown arguments.
699
+ *
700
+ * argv => operands, unknown
701
+ * --known kkk op => [op], []
702
+ * op --known kkk => [op], []
703
+ * sub --unknown uuu op => [sub], [--unknown uuu op]
704
+ * sub -- --unknown uuu op => [sub --unknown uuu op], []
705
+ */
706
+ parseOptions(argv: string[]): ParseOptionsResult;
707
+
708
+ /**
709
+ * Return an object containing local option values as key-value pairs
710
+ */
711
+ opts<T extends OptionValues>(): T;
712
+
713
+ /**
714
+ * Return an object containing merged local and global option values as key-value pairs.
715
+ */
716
+ optsWithGlobals<T extends OptionValues>(): T;
717
+
718
+ /**
719
+ * Set the description.
720
+ *
721
+ * @returns `this` command for chaining
722
+ */
723
+
724
+ description(str: string): this;
725
+ /** @deprecated since v8, instead use .argument to add command argument with description */
726
+ description(str: string, argsDescription: Record<string, string>): this;
727
+ /**
728
+ * Get the description.
729
+ */
730
+ description(): string;
731
+
732
+ /**
733
+ * Set the summary. Used when listed as subcommand of parent.
734
+ *
735
+ * @returns `this` command for chaining
736
+ */
737
+
738
+ summary(str: string): this;
739
+ /**
740
+ * Get the summary.
741
+ */
742
+ summary(): string;
743
+
744
+ /**
745
+ * Set an alias for the command.
746
+ *
747
+ * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
748
+ *
749
+ * @returns `this` command for chaining
750
+ */
751
+ alias(alias: string): this;
752
+ /**
753
+ * Get alias for the command.
754
+ */
755
+ alias(): string;
756
+
757
+ /**
758
+ * Set aliases for the command.
759
+ *
760
+ * Only the first alias is shown in the auto-generated help.
761
+ *
762
+ * @returns `this` command for chaining
763
+ */
764
+ aliases(aliases: readonly string[]): this;
765
+ /**
766
+ * Get aliases for the command.
767
+ */
768
+ aliases(): string[];
769
+
770
+ /**
771
+ * Set the command usage.
772
+ *
773
+ * @returns `this` command for chaining
774
+ */
775
+ usage(str: string): this;
776
+ /**
777
+ * Get the command usage.
778
+ */
779
+ usage(): string;
780
+
781
+ /**
782
+ * Set the name of the command.
783
+ *
784
+ * @returns `this` command for chaining
785
+ */
786
+ name(str: string): this;
787
+ /**
788
+ * Get the name of the command.
789
+ */
790
+ name(): string;
791
+
792
+ /**
793
+ * Set the name of the command from script filename, such as process.argv[1],
794
+ * or require.main.filename, or __filename.
795
+ *
796
+ * (Used internally and public although not documented in README.)
797
+ *
798
+ * @example
799
+ * ```ts
800
+ * program.nameFromFilename(require.main.filename);
801
+ * ```
802
+ *
803
+ * @returns `this` command for chaining
804
+ */
805
+ nameFromFilename(filename: string): this;
806
+
807
+ /**
808
+ * Set the directory for searching for executable subcommands of this command.
809
+ *
810
+ * @example
811
+ * ```ts
812
+ * program.executableDir(__dirname);
813
+ * // or
814
+ * program.executableDir('subcommands');
815
+ * ```
816
+ *
817
+ * @returns `this` command for chaining
818
+ */
819
+ executableDir(path: string): this;
820
+ /**
821
+ * Get the executable search directory.
822
+ */
823
+ executableDir(): string;
824
+
825
+ /**
826
+ * Output help information for this command.
827
+ *
828
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
829
+ *
830
+ */
831
+ outputHelp(context?: HelpContext): void;
832
+ /** @deprecated since v7 */
833
+ outputHelp(cb?: (str: string) => string): void;
834
+
835
+ /**
836
+ * Return command help documentation.
837
+ */
838
+ helpInformation(context?: HelpContext): string;
839
+
840
+ /**
841
+ * You can pass in flags and a description to override the help
842
+ * flags and help description for your command. Pass in false
843
+ * to disable the built-in help option.
844
+ */
845
+ helpOption(flags?: string | boolean, description?: string): this;
846
+
847
+ /**
848
+ * Output help information and exit.
849
+ *
850
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
851
+ */
852
+ help(context?: HelpContext): never;
853
+ /** @deprecated since v7 */
854
+ help(cb?: (str: string) => string): never;
855
+
856
+ /**
857
+ * Add additional text to be displayed with the built-in help.
858
+ *
859
+ * Position is 'before' or 'after' to affect just this command,
860
+ * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
861
+ */
862
+ addHelpText(position: AddHelpTextPosition, text: string): this;
863
+ addHelpText(position: AddHelpTextPosition, text: (context: AddHelpTextContext) => string): this;
864
+
865
+ /**
866
+ * Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
867
+ */
868
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
869
+ }
870
+
871
+ export interface CommandOptions {
872
+ hidden?: boolean;
873
+ isDefault?: boolean;
874
+ /** @deprecated since v7, replaced by hidden */
875
+ noHelp?: boolean;
876
+ }
877
+ export interface ExecutableCommandOptions extends CommandOptions {
878
+ executableFile?: string;
879
+ }
880
+
881
+ export interface ParseOptionsResult {
882
+ operands: string[];
883
+ unknown: string[];
884
+ }
885
+
886
+ export function createCommand(name?: string): Command;
887
+ export function createOption(flags: string, description?: string): Option;
888
+ export function createArgument(name: string, description?: string): Argument;
406
889
 
407
- // Declaring namespace AND global
408
- // eslint-disable-next-line @typescript-eslint/no-redeclare
409
- declare const commander: commander.CommanderStatic;
410
- export = commander;
890
+ export const program: Command;