@foxford/cli 1.0.0-beta-6f7848f0-20250318 → 1.1.0-beta-0acd9fac-20250513

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.
Files changed (5) hide show
  1. package/README.mdx +56 -1
  2. package/fox.d.ts +1031 -0
  3. package/fox.js +682 -643
  4. package/fox.js.map +1 -1
  5. package/package.json +7 -4
package/fox.d.ts ADDED
@@ -0,0 +1,1031 @@
1
+ declare abstract class AbstractAction<Options = FoxfordTools.ProcessInput[]> {
2
+ protected program: FoxfordTools.Program;
3
+ constructor(program: FoxfordTools.Program);
4
+ abstract handle(options?: Options, params?: string[]): Promise<void>;
5
+ }
6
+ declare abstract class AbstractCommand<Options = unknown> {
7
+ protected action: AbstractAction<Options>;
8
+ constructor(action: AbstractAction<Options>);
9
+ abstract id: string;
10
+ abstract load(program: FoxfordTools.Program): Promise<void> | void;
11
+ }
12
+ declare class Argument {
13
+ description: string;
14
+ required: boolean;
15
+ variadic: boolean;
16
+ defaultValue?: any;
17
+ defaultValueDescription?: string;
18
+ argChoices?: string[];
19
+ /**
20
+ * Initialize a new command argument with the given name and description.
21
+ * The default is that the argument is required, and you can explicitly
22
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
23
+ */
24
+ constructor(arg: string, description?: string);
25
+ /**
26
+ * Return argument name.
27
+ */
28
+ name(): string;
29
+ /**
30
+ * Set the default value, and optionally supply the description to be displayed in the help.
31
+ */
32
+ default(value: unknown, description?: string): this;
33
+ /**
34
+ * Set the custom handler for processing CLI command arguments into argument values.
35
+ */
36
+ argParser<T>(fn: (value: string, previous: T) => T): this;
37
+ /**
38
+ * Only allow argument value to be one of choices.
39
+ */
40
+ choices(values: readonly string[]): this;
41
+ /**
42
+ * Make argument required.
43
+ */
44
+ argRequired(): this;
45
+ /**
46
+ * Make argument optional.
47
+ */
48
+ argOptional(): this;
49
+ }
50
+ declare class Command {
51
+ args: string[];
52
+ processedArgs: any[];
53
+ readonly commands: readonly Command[];
54
+ readonly options: readonly Option$1[];
55
+ readonly registeredArguments: readonly Argument[];
56
+ parent: Command | null;
57
+ constructor(name?: string);
58
+ /**
59
+ * Set the program version to `str`.
60
+ *
61
+ * This method auto-registers the "-V, --version" flag
62
+ * which will print the version number when passed.
63
+ *
64
+ * You can optionally supply the flags and description to override the defaults.
65
+ */
66
+ version(str: string, flags?: string, description?: string): this;
67
+ /**
68
+ * Get the program version.
69
+ */
70
+ version(): string | undefined;
71
+ /**
72
+ * Define a command, implemented using an action handler.
73
+ *
74
+ * @remarks
75
+ * The command description is supplied using `.description`, not as a parameter to `.command`.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * program
80
+ * .command('clone <source> [destination]')
81
+ * .description('clone a repository into a newly created directory')
82
+ * .action((source, destination) => {
83
+ * console.log('clone command called');
84
+ * });
85
+ * ```
86
+ *
87
+ * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
88
+ * @param opts - configuration options
89
+ * @returns new command
90
+ */
91
+ command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this["createCommand"]>;
92
+ /**
93
+ * Define a command, implemented in a separate executable file.
94
+ *
95
+ * @remarks
96
+ * The command description is supplied as the second parameter to `.command`.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * program
101
+ * .command('start <service>', 'start named service')
102
+ * .command('stop [service]', 'stop named service, or all if no name supplied');
103
+ * ```
104
+ *
105
+ * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
106
+ * @param description - description of executable command
107
+ * @param opts - configuration options
108
+ * @returns `this` command for chaining
109
+ */
110
+ command(nameAndArgs: string, description: string, opts?: ExecutableCommandOptions): this;
111
+ /**
112
+ * Factory routine to create a new unattached command.
113
+ *
114
+ * See .command() for creating an attached subcommand, which uses this routine to
115
+ * create the command. You can override createCommand to customise subcommands.
116
+ */
117
+ createCommand(name?: string): Command;
118
+ /**
119
+ * Add a prepared subcommand.
120
+ *
121
+ * See .command() for creating an attached subcommand which inherits settings from its parent.
122
+ *
123
+ * @returns `this` command for chaining
124
+ */
125
+ addCommand(cmd: Command, opts?: CommandOptions): this;
126
+ /**
127
+ * Factory routine to create a new unattached argument.
128
+ *
129
+ * See .argument() for creating an attached argument, which uses this routine to
130
+ * create the argument. You can override createArgument to return a custom argument.
131
+ */
132
+ createArgument(name: string, description?: string): Argument;
133
+ /**
134
+ * Define argument syntax for command.
135
+ *
136
+ * The default is that the argument is required, and you can explicitly
137
+ * indicate this with <> around the name. Put [] around the name for an optional argument.
138
+ *
139
+ * @example
140
+ * ```
141
+ * program.argument('<input-file>');
142
+ * program.argument('[output-file]');
143
+ * ```
144
+ *
145
+ * @returns `this` command for chaining
146
+ */
147
+ argument<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
148
+ argument(name: string, description?: string, defaultValue?: unknown): this;
149
+ /**
150
+ * Define argument syntax for command, adding a prepared argument.
151
+ *
152
+ * @returns `this` command for chaining
153
+ */
154
+ addArgument(arg: Argument): this;
155
+ /**
156
+ * Define argument syntax for command, adding multiple at once (without descriptions).
157
+ *
158
+ * See also .argument().
159
+ *
160
+ * @example
161
+ * ```
162
+ * program.arguments('<cmd> [env]');
163
+ * ```
164
+ *
165
+ * @returns `this` command for chaining
166
+ */
167
+ arguments(names: string): this;
168
+ /**
169
+ * Customise or override default help command. By default a help command is automatically added if your command has subcommands.
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * program.helpCommand('help [cmd]');
174
+ * program.helpCommand('help [cmd]', 'show help');
175
+ * program.helpCommand(false); // suppress default help command
176
+ * program.helpCommand(true); // add help command even if no subcommands
177
+ * ```
178
+ */
179
+ helpCommand(nameAndArgs: string, description?: string): this;
180
+ helpCommand(enable: boolean): this;
181
+ /**
182
+ * Add prepared custom help command.
183
+ */
184
+ addHelpCommand(cmd: Command): this;
185
+ /** @deprecated since v12, instead use helpCommand */
186
+ addHelpCommand(nameAndArgs: string, description?: string): this;
187
+ /** @deprecated since v12, instead use helpCommand */
188
+ addHelpCommand(enable?: boolean): this;
189
+ /**
190
+ * Add hook for life cycle event.
191
+ */
192
+ hook(event: HookEvent, listener: (thisCommand: Command, actionCommand: Command) => void | Promise<void>): this;
193
+ /**
194
+ * Register callback to use as replacement for calling process.exit.
195
+ */
196
+ exitOverride(callback?: (err: CommanderError) => never | void): this;
197
+ /**
198
+ * Display error message and exit (or call exitOverride).
199
+ */
200
+ error(message: string, errorOptions?: ErrorOptions$1): never;
201
+ /**
202
+ * You can customise the help with a subclass of Help by overriding createHelp,
203
+ * or by overriding Help properties using configureHelp().
204
+ */
205
+ createHelp(): Help;
206
+ /**
207
+ * You can customise the help by overriding Help properties using configureHelp(),
208
+ * or with a subclass of Help by overriding createHelp().
209
+ */
210
+ configureHelp(configuration: HelpConfiguration): this;
211
+ /** Get configuration */
212
+ configureHelp(): HelpConfiguration;
213
+ /**
214
+ * The default output goes to stdout and stderr. You can customise this for special
215
+ * applications. You can also customise the display of errors by overriding outputError.
216
+ *
217
+ * The configuration properties are all functions:
218
+ * ```
219
+ * // functions to change where being written, stdout and stderr
220
+ * writeOut(str)
221
+ * writeErr(str)
222
+ * // matching functions to specify width for wrapping help
223
+ * getOutHelpWidth()
224
+ * getErrHelpWidth()
225
+ * // functions based on what is being written out
226
+ * outputError(str, write) // used for displaying errors, and not used for displaying help
227
+ * ```
228
+ */
229
+ configureOutput(configuration: OutputConfiguration): this;
230
+ /** Get configuration */
231
+ configureOutput(): OutputConfiguration;
232
+ /**
233
+ * Copy settings that are useful to have in common across root command and subcommands.
234
+ *
235
+ * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
236
+ */
237
+ copyInheritedSettings(sourceCommand: Command): this;
238
+ /**
239
+ * Display the help or a custom message after an error occurs.
240
+ */
241
+ showHelpAfterError(displayHelp?: boolean | string): this;
242
+ /**
243
+ * Display suggestion of similar commands for unknown commands, or options for unknown options.
244
+ */
245
+ showSuggestionAfterError(displaySuggestion?: boolean): this;
246
+ /**
247
+ * Register callback `fn` for the command.
248
+ *
249
+ * @example
250
+ * ```
251
+ * program
252
+ * .command('serve')
253
+ * .description('start service')
254
+ * .action(function() {
255
+ * // do work here
256
+ * });
257
+ * ```
258
+ *
259
+ * @returns `this` command for chaining
260
+ */
261
+ action(fn: (this: this, ...args: any[]) => void | Promise<void>): this;
262
+ /**
263
+ * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
264
+ *
265
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
266
+ * option-argument is indicated by `<>` and an optional option-argument by `[]`.
267
+ *
268
+ * See the README for more details, and see also addOption() and requiredOption().
269
+ *
270
+ * @example
271
+ *
272
+ * ```js
273
+ * program
274
+ * .option('-p, --pepper', 'add pepper')
275
+ * .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
276
+ * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
277
+ * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
278
+ * ```
279
+ *
280
+ * @returns `this` command for chaining
281
+ */
282
+ option(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
283
+ option<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
284
+ /** @deprecated since v7, instead use choices or a custom function */
285
+ option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;
286
+ /**
287
+ * Define a required option, which must have a value after parsing. This usually means
288
+ * the option must be specified on the command line. (Otherwise the same as .option().)
289
+ *
290
+ * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
291
+ */
292
+ requiredOption(flags: string, description?: string, defaultValue?: string | boolean | string[]): this;
293
+ requiredOption<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
294
+ /** @deprecated since v7, instead use choices or a custom function */
295
+ requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;
296
+ /**
297
+ * Factory routine to create a new unattached option.
298
+ *
299
+ * See .option() for creating an attached option, which uses this routine to
300
+ * create the option. You can override createOption to return a custom option.
301
+ */
302
+ createOption(flags: string, description?: string): Option$1;
303
+ /**
304
+ * Add a prepared Option.
305
+ *
306
+ * See .option() and .requiredOption() for creating and attaching an option in a single call.
307
+ */
308
+ addOption(option: Option$1): this;
309
+ /**
310
+ * Whether to store option values as properties on command object,
311
+ * or store separately (specify false). In both cases the option values can be accessed using .opts().
312
+ *
313
+ * @returns `this` command for chaining
314
+ */
315
+ storeOptionsAsProperties<T extends OptionValues>(): this & T;
316
+ storeOptionsAsProperties<T extends OptionValues>(storeAsProperties: true): this & T;
317
+ storeOptionsAsProperties(storeAsProperties?: boolean): this;
318
+ /**
319
+ * Retrieve option value.
320
+ */
321
+ getOptionValue(key: string): any;
322
+ /**
323
+ * Store option value.
324
+ */
325
+ setOptionValue(key: string, value: unknown): this;
326
+ /**
327
+ * Store option value and where the value came from.
328
+ */
329
+ setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this;
330
+ /**
331
+ * Get source of option value.
332
+ */
333
+ getOptionValueSource(key: string): OptionValueSource | undefined;
334
+ /**
335
+ * Get source of option value. See also .optsWithGlobals().
336
+ */
337
+ getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined;
338
+ /**
339
+ * Alter parsing of short flags with optional values.
340
+ *
341
+ * @example
342
+ * ```
343
+ * // for `.option('-f,--flag [value]'):
344
+ * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
345
+ * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
346
+ * ```
347
+ *
348
+ * @returns `this` command for chaining
349
+ */
350
+ combineFlagAndOptionalValue(combine?: boolean): this;
351
+ /**
352
+ * Allow unknown options on the command line.
353
+ *
354
+ * @returns `this` command for chaining
355
+ */
356
+ allowUnknownOption(allowUnknown?: boolean): this;
357
+ /**
358
+ * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
359
+ *
360
+ * @returns `this` command for chaining
361
+ */
362
+ allowExcessArguments(allowExcess?: boolean): this;
363
+ /**
364
+ * Enable positional options. Positional means global options are specified before subcommands which lets
365
+ * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
366
+ *
367
+ * The default behaviour is non-positional and global options may appear anywhere on the command line.
368
+ *
369
+ * @returns `this` command for chaining
370
+ */
371
+ enablePositionalOptions(positional?: boolean): this;
372
+ /**
373
+ * Pass through options that come after command-arguments rather than treat them as command-options,
374
+ * so actual command-options come before command-arguments. Turning this on for a subcommand requires
375
+ * positional options to have been enabled on the program (parent commands).
376
+ *
377
+ * The default behaviour is non-positional and options may appear before or after command-arguments.
378
+ *
379
+ * @returns `this` command for chaining
380
+ */
381
+ passThroughOptions(passThrough?: boolean): this;
382
+ /**
383
+ * Parse `argv`, setting options and invoking commands when defined.
384
+ *
385
+ * Use parseAsync instead of parse if any of your action handlers are async.
386
+ *
387
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
388
+ *
389
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
390
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
391
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
392
+ * - `'user'`: just user arguments
393
+ *
394
+ * @example
395
+ * ```
396
+ * program.parse(); // parse process.argv and auto-detect electron and special node flags
397
+ * program.parse(process.argv); // assume argv[0] is app and argv[1] is script
398
+ * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
399
+ * ```
400
+ *
401
+ * @returns `this` command for chaining
402
+ */
403
+ parse(argv?: readonly string[], parseOptions?: ParseOptions): this;
404
+ /**
405
+ * Parse `argv`, setting options and invoking commands when defined.
406
+ *
407
+ * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
408
+ *
409
+ * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
410
+ * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
411
+ * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
412
+ * - `'user'`: just user arguments
413
+ *
414
+ * @example
415
+ * ```
416
+ * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
417
+ * await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
418
+ * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
419
+ * ```
420
+ *
421
+ * @returns Promise
422
+ */
423
+ parseAsync(argv?: readonly string[], parseOptions?: ParseOptions): Promise<this>;
424
+ /**
425
+ * Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
426
+ * Not usually called directly, but available for subclasses to save their custom state.
427
+ *
428
+ * This is called in a lazy way. Only commands used in parsing chain will have state saved.
429
+ */
430
+ saveStateBeforeParse(): void;
431
+ /**
432
+ * Restore state before parse for calls after the first.
433
+ * Not usually called directly, but available for subclasses to save their custom state.
434
+ *
435
+ * This is called in a lazy way. Only commands used in parsing chain will have state restored.
436
+ */
437
+ restoreStateBeforeParse(): void;
438
+ /**
439
+ * Parse options from `argv` removing known options,
440
+ * and return argv split into operands and unknown arguments.
441
+ *
442
+ * Side effects: modifies command by storing options. Does not reset state if called again.
443
+ *
444
+ * argv => operands, unknown
445
+ * --known kkk op => [op], []
446
+ * op --known kkk => [op], []
447
+ * sub --unknown uuu op => [sub], [--unknown uuu op]
448
+ * sub -- --unknown uuu op => [sub --unknown uuu op], []
449
+ */
450
+ parseOptions(argv: string[]): ParseOptionsResult;
451
+ /**
452
+ * Return an object containing local option values as key-value pairs
453
+ */
454
+ opts<T extends OptionValues>(): T;
455
+ /**
456
+ * Return an object containing merged local and global option values as key-value pairs.
457
+ */
458
+ optsWithGlobals<T extends OptionValues>(): T;
459
+ /**
460
+ * Set the description.
461
+ *
462
+ * @returns `this` command for chaining
463
+ */
464
+ description(str: string): this;
465
+ /** @deprecated since v8, instead use .argument to add command argument with description */
466
+ description(str: string, argsDescription: Record<string, string>): this;
467
+ /**
468
+ * Get the description.
469
+ */
470
+ description(): string;
471
+ /**
472
+ * Set the summary. Used when listed as subcommand of parent.
473
+ *
474
+ * @returns `this` command for chaining
475
+ */
476
+ summary(str: string): this;
477
+ /**
478
+ * Get the summary.
479
+ */
480
+ summary(): string;
481
+ /**
482
+ * Set an alias for the command.
483
+ *
484
+ * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
485
+ *
486
+ * @returns `this` command for chaining
487
+ */
488
+ alias(alias: string): this;
489
+ /**
490
+ * Get alias for the command.
491
+ */
492
+ alias(): string;
493
+ /**
494
+ * Set aliases for the command.
495
+ *
496
+ * Only the first alias is shown in the auto-generated help.
497
+ *
498
+ * @returns `this` command for chaining
499
+ */
500
+ aliases(aliases: readonly string[]): this;
501
+ /**
502
+ * Get aliases for the command.
503
+ */
504
+ aliases(): string[];
505
+ /**
506
+ * Set the command usage.
507
+ *
508
+ * @returns `this` command for chaining
509
+ */
510
+ usage(str: string): this;
511
+ /**
512
+ * Get the command usage.
513
+ */
514
+ usage(): string;
515
+ /**
516
+ * Set the name of the command.
517
+ *
518
+ * @returns `this` command for chaining
519
+ */
520
+ name(str: string): this;
521
+ /**
522
+ * Get the name of the command.
523
+ */
524
+ name(): string;
525
+ /**
526
+ * Set the name of the command from script filename, such as process.argv[1],
527
+ * or require.main.filename, or __filename.
528
+ *
529
+ * (Used internally and public although not documented in README.)
530
+ *
531
+ * @example
532
+ * ```ts
533
+ * program.nameFromFilename(require.main.filename);
534
+ * ```
535
+ *
536
+ * @returns `this` command for chaining
537
+ */
538
+ nameFromFilename(filename: string): this;
539
+ /**
540
+ * Set the directory for searching for executable subcommands of this command.
541
+ *
542
+ * @example
543
+ * ```ts
544
+ * program.executableDir(__dirname);
545
+ * // or
546
+ * program.executableDir('subcommands');
547
+ * ```
548
+ *
549
+ * @returns `this` command for chaining
550
+ */
551
+ executableDir(path: string): this;
552
+ /**
553
+ * Get the executable search directory.
554
+ */
555
+ executableDir(): string | null;
556
+ /**
557
+ * Output help information for this command.
558
+ *
559
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
560
+ *
561
+ */
562
+ outputHelp(context?: HelpContext): void;
563
+ /** @deprecated since v7 */
564
+ outputHelp(cb?: (str: string) => string): void;
565
+ /**
566
+ * Return command help documentation.
567
+ */
568
+ helpInformation(context?: HelpContext): string;
569
+ /**
570
+ * You can pass in flags and a description to override the help
571
+ * flags and help description for your command. Pass in false
572
+ * to disable the built-in help option.
573
+ */
574
+ helpOption(flags?: string | boolean, description?: string): this;
575
+ /**
576
+ * Supply your own option to use for the built-in help option.
577
+ * This is an alternative to using helpOption() to customise the flags and description etc.
578
+ */
579
+ addHelpOption(option: Option$1): this;
580
+ /**
581
+ * Output help information and exit.
582
+ *
583
+ * Outputs built-in help, and custom text added using `.addHelpText()`.
584
+ */
585
+ help(context?: HelpContext): never;
586
+ /** @deprecated since v7 */
587
+ help(cb?: (str: string) => string): never;
588
+ /**
589
+ * Add additional text to be displayed with the built-in help.
590
+ *
591
+ * Position is 'before' or 'after' to affect just this command,
592
+ * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
593
+ */
594
+ addHelpText(position: AddHelpTextPosition, text: string): this;
595
+ addHelpText(position: AddHelpTextPosition, text: (context: AddHelpTextContext) => string): this;
596
+ /**
597
+ * Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
598
+ */
599
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
600
+ }
601
+ declare class CommanderError extends Error {
602
+ code: string;
603
+ exitCode: number;
604
+ message: string;
605
+ nestedError?: string;
606
+ /**
607
+ * Constructs the CommanderError class
608
+ * @param exitCode - suggested exit code which could be used with process.exit
609
+ * @param code - an id string representing the error
610
+ * @param message - human-readable description of the error
611
+ */
612
+ constructor(exitCode: number, code: string, message: string);
613
+ }
614
+ declare class Help {
615
+ /** output helpWidth, long lines are wrapped to fit */
616
+ helpWidth?: number;
617
+ minWidthToWrap: number;
618
+ sortSubcommands: boolean;
619
+ sortOptions: boolean;
620
+ showGlobalOptions: boolean;
621
+ constructor();
622
+ /*
623
+ * prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
624
+ * and just before calling `formatHelp()`.
625
+ *
626
+ * Commander just uses the helpWidth and the others are provided for subclasses.
627
+ */
628
+ prepareContext(contextOptions: {
629
+ error?: boolean;
630
+ helpWidth?: number;
631
+ outputHasColors?: boolean;
632
+ }): void;
633
+ /** Get the command term to show in the list of subcommands. */
634
+ subcommandTerm(cmd: Command): string;
635
+ /** Get the command summary to show in the list of subcommands. */
636
+ subcommandDescription(cmd: Command): string;
637
+ /** Get the option term to show in the list of options. */
638
+ optionTerm(option: Option$1): string;
639
+ /** Get the option description to show in the list of options. */
640
+ optionDescription(option: Option$1): string;
641
+ /** Get the argument term to show in the list of arguments. */
642
+ argumentTerm(argument: Argument): string;
643
+ /** Get the argument description to show in the list of arguments. */
644
+ argumentDescription(argument: Argument): string;
645
+ /** Get the command usage to be displayed at the top of the built-in help. */
646
+ commandUsage(cmd: Command): string;
647
+ /** Get the description for the command. */
648
+ commandDescription(cmd: Command): string;
649
+ /** Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one. */
650
+ visibleCommands(cmd: Command): Command[];
651
+ /** Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one. */
652
+ visibleOptions(cmd: Command): Option$1[];
653
+ /** Get an array of the visible global options. (Not including help.) */
654
+ visibleGlobalOptions(cmd: Command): Option$1[];
655
+ /** Get an array of the arguments which have descriptions. */
656
+ visibleArguments(cmd: Command): Argument[];
657
+ /** Get the longest command term length. */
658
+ longestSubcommandTermLength(cmd: Command, helper: Help): number;
659
+ /** Get the longest option term length. */
660
+ longestOptionTermLength(cmd: Command, helper: Help): number;
661
+ /** Get the longest global option term length. */
662
+ longestGlobalOptionTermLength(cmd: Command, helper: Help): number;
663
+ /** Get the longest argument term length. */
664
+ longestArgumentTermLength(cmd: Command, helper: Help): number;
665
+ /** Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations. */
666
+ displayWidth(str: string): number;
667
+ /** Style the titles. Called with 'Usage:', 'Options:', etc. */
668
+ styleTitle(title: string): string;
669
+ /** Usage: <str> */
670
+ styleUsage(str: string): string;
671
+ /** Style for command name in usage string. */
672
+ styleCommandText(str: string): string;
673
+ styleCommandDescription(str: string): string;
674
+ styleOptionDescription(str: string): string;
675
+ styleSubcommandDescription(str: string): string;
676
+ styleArgumentDescription(str: string): string;
677
+ /** Base style used by descriptions. */
678
+ styleDescriptionText(str: string): string;
679
+ styleOptionTerm(str: string): string;
680
+ styleSubcommandTerm(str: string): string;
681
+ styleArgumentTerm(str: string): string;
682
+ /** Base style used in terms and usage for options. */
683
+ styleOptionText(str: string): string;
684
+ /** Base style used in terms and usage for subcommands. */
685
+ styleSubcommandText(str: string): string;
686
+ /** Base style used in terms and usage for arguments. */
687
+ styleArgumentText(str: string): string;
688
+ /** Calculate the pad width from the maximum term length. */
689
+ padWidth(cmd: Command, helper: Help): number;
690
+ /**
691
+ * Wrap a string at whitespace, preserving existing line breaks.
692
+ * Wrapping is skipped if the width is less than `minWidthToWrap`.
693
+ */
694
+ boxWrap(str: string, width: number): string;
695
+ /** Detect manually wrapped and indented strings by checking for line break followed by whitespace. */
696
+ preformatted(str: string): boolean;
697
+ /**
698
+ * Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
699
+ *
700
+ * So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
701
+ * TTT DDD DDDD
702
+ * DD DDD
703
+ */
704
+ formatItem(term: string, termWidth: number, description: string, helper: Help): string;
705
+ /** Generate the built-in help text. */
706
+ formatHelp(cmd: Command, helper: Help): string;
707
+ }
708
+ declare class Option$1 {
709
+ flags: string;
710
+ description: string;
711
+ required: boolean; // A value must be supplied when the option is specified.
712
+ optional: boolean; // A value is optional when the option is specified.
713
+ variadic: boolean;
714
+ mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line.
715
+ short?: string;
716
+ long?: string;
717
+ negate: boolean;
718
+ defaultValue?: any;
719
+ defaultValueDescription?: string;
720
+ presetArg?: unknown;
721
+ envVar?: string;
722
+ parseArg?: <T>(value: string, previous: T) => T;
723
+ hidden: boolean;
724
+ argChoices?: string[];
725
+ constructor(flags: string, description?: string);
726
+ /**
727
+ * Set the default value, and optionally supply the description to be displayed in the help.
728
+ */
729
+ default(value: unknown, description?: string): this;
730
+ /**
731
+ * Preset to use when option used without option-argument, especially optional but also boolean and negated.
732
+ * The custom processing (parseArg) is called.
733
+ *
734
+ * @example
735
+ * ```ts
736
+ * new Option('--color').default('GREYSCALE').preset('RGB');
737
+ * new Option('--donate [amount]').preset('20').argParser(parseFloat);
738
+ * ```
739
+ */
740
+ preset(arg: unknown): this;
741
+ /**
742
+ * Add option name(s) that conflict with this option.
743
+ * An error will be displayed if conflicting options are found during parsing.
744
+ *
745
+ * @example
746
+ * ```ts
747
+ * new Option('--rgb').conflicts('cmyk');
748
+ * new Option('--js').conflicts(['ts', 'jsx']);
749
+ * ```
750
+ */
751
+ conflicts(names: string | string[]): this;
752
+ /**
753
+ * Specify implied option values for when this option is set and the implied options are not.
754
+ *
755
+ * The custom processing (parseArg) is not called on the implied values.
756
+ *
757
+ * @example
758
+ * program
759
+ * .addOption(new Option('--log', 'write logging information to file'))
760
+ * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
761
+ */
762
+ implies(optionValues: OptionValues): this;
763
+ /**
764
+ * Set environment variable to check for option value.
765
+ *
766
+ * An environment variables is only used if when processed the current option value is
767
+ * undefined, or the source of the current value is 'default' or 'config' or 'env'.
768
+ */
769
+ env(name: string): this;
770
+ /**
771
+ * Set the custom handler for processing CLI option arguments into option values.
772
+ */
773
+ argParser<T>(fn: (value: string, previous: T) => T): this;
774
+ /**
775
+ * Whether the option is mandatory and must have a value after parsing.
776
+ */
777
+ makeOptionMandatory(mandatory?: boolean): this;
778
+ /**
779
+ * Hide option in help.
780
+ */
781
+ hideHelp(hide?: boolean): this;
782
+ /**
783
+ * Only allow option value to be one of choices.
784
+ */
785
+ choices(values: readonly string[]): this;
786
+ /**
787
+ * Return option name.
788
+ */
789
+ name(): string;
790
+ /**
791
+ * Return option name, in a camelcase format that can be used
792
+ * as an object attribute key.
793
+ */
794
+ attributeName(): string;
795
+ /**
796
+ * Return whether a boolean option.
797
+ *
798
+ * Options are one of boolean, negated, required argument, or optional argument.
799
+ */
800
+ isBoolean(): boolean;
801
+ }
802
+ declare const logger: HierarchicalLogger;
803
+ export interface AddHelpTextContext {
804
+ // passed to text function used with .addHelpText()
805
+ error: boolean;
806
+ command: Command;
807
+ }
808
+ export interface CommandOptions {
809
+ hidden?: boolean;
810
+ isDefault?: boolean;
811
+ /** @deprecated since v7, replaced by hidden */
812
+ noHelp?: boolean;
813
+ }
814
+ export interface ExecutableCommandOptions extends CommandOptions {
815
+ executableFile?: string;
816
+ }
817
+ export interface HelpContext {
818
+ // optional parameter for .help() and .outputHelp()
819
+ error: boolean;
820
+ }
821
+ export interface HierarchicalLogger extends Logger {
822
+ id: Id;
823
+ parent: HierarchicalLogger | null;
824
+ debugEnabled: boolean;
825
+ children: Set<HierarchicalLogger>;
826
+ name: string;
827
+ getLogger(name: string): HierarchicalLogger;
828
+ setDebug(enabled: boolean): void;
829
+ getFullName(): string;
830
+ isDebugEnabled(): boolean;
831
+ getDebugPattern(): string | null;
832
+ }
833
+ export interface LogLevel {
834
+ TRACE: 0;
835
+ DEBUG: 1;
836
+ INFO: 2;
837
+ WARN: 3;
838
+ ERROR: 4;
839
+ SILENT: 5;
840
+ }
841
+ export interface Logger {
842
+ /**
843
+ * Available log levels.
844
+ */
845
+ readonly levels: LogLevel;
846
+ /**
847
+ * Plugin API entry point. This will be called for each enabled method each time the level is set
848
+ * (including initially), and should return a MethodFactory to be used for the given log method, at the given level,
849
+ * for a logger with the given name. If you'd like to retain all the reliability and features of loglevel, it's
850
+ * recommended that this wraps the initially provided value of log.methodFactory
851
+ */
852
+ methodFactory: MethodFactory;
853
+ /**
854
+ * Output trace message to console.
855
+ * This will also include a full stack trace
856
+ *
857
+ * @param msg any data to log to the console
858
+ */
859
+ trace(...msg: any[]): void;
860
+ /**
861
+ * Output debug message to console including appropriate icons
862
+ *
863
+ * @param msg any data to log to the console
864
+ */
865
+ debug(...msg: any[]): void;
866
+ /**
867
+ * Output debug message to console including appropriate icons
868
+ *
869
+ * @param msg any data to log to the console
870
+ */
871
+ log(...msg: any[]): void;
872
+ /**
873
+ * Output info message to console including appropriate icons
874
+ *
875
+ * @param msg any data to log to the console
876
+ */
877
+ info(...msg: any[]): void;
878
+ /**
879
+ * Output warn message to console including appropriate icons
880
+ *
881
+ * @param msg any data to log to the console
882
+ */
883
+ warn(...msg: any[]): void;
884
+ /**
885
+ * Output error message to console including appropriate icons
886
+ *
887
+ * @param msg any data to log to the console
888
+ */
889
+ error(...msg: any[]): void;
890
+ /**
891
+ * This disables all logging below the given level, so that after a log.setLevel("warn") call log.warn("something")
892
+ * or log.error("something") will output messages, but log.info("something") will not.
893
+ *
894
+ * @param level as a string, like 'error' (case-insensitive) or as a number from 0 to 5 (or as log.levels. values)
895
+ * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling
896
+ * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass
897
+ * false as the optional 'persist' second argument, persistence will be skipped.
898
+ */
899
+ setLevel(level: LogLevelDesc, persist?: boolean): void;
900
+ /**
901
+ * Returns the current logging level, as a value from LogLevel.
902
+ * It's very unlikely you'll need to use this for normal application logging; it's provided partly to help plugin
903
+ * development, and partly to let you optimize logging code as below, where debug data is only generated if the
904
+ * level is set such that it'll actually be logged. This probably doesn't affect you, unless you've run profiling
905
+ * on your code and you have hard numbers telling you that your log data generation is a real performance problem.
906
+ */
907
+ getLevel(): LogLevel[keyof LogLevel];
908
+ /**
909
+ * This sets the current log level only if one has not been persisted and can’t be loaded. This is useful when
910
+ * initializing scripts; if a developer or user has previously called setLevel(), this won’t alter their settings.
911
+ * For example, your application might set the log level to error in a production environment, but when debugging
912
+ * an issue, you might call setLevel("trace") on the console to see all the logs. If that error setting was set
913
+ * using setDefaultLevel(), it will still say as trace on subsequent page loads and refreshes instead of resetting
914
+ * to error.
915
+ *
916
+ * The level argument takes is the same values that you might pass to setLevel(). Levels set using
917
+ * setDefaultLevel() never persist to subsequent page loads.
918
+ *
919
+ * @param level as a string, like 'error' (case-insensitive) or as a number from 0 to 5 (or as log.levels. values)
920
+ */
921
+ setDefaultLevel(level: LogLevelDesc): void;
922
+ /**
923
+ * This resets the current log level to the default level (or `warn` if no explicit default was set) and clears
924
+ * the persisted level if one was previously persisted.
925
+ */
926
+ resetLevel(): void;
927
+ /**
928
+ * This enables all log messages, and is equivalent to log.setLevel("trace").
929
+ *
930
+ * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling
931
+ * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass
932
+ * false as the optional 'persist' second argument, persistence will be skipped.
933
+ */
934
+ enableAll(persist?: boolean): void;
935
+ /**
936
+ * This disables all log messages, and is equivalent to log.setLevel("silent").
937
+ *
938
+ * @param persist Where possible the log level will be persisted. LocalStorage will be used if available, falling
939
+ * back to cookies if not. If neither is available in the current environment (i.e. in Node), or if you pass
940
+ * false as the optional 'persist' second argument, persistence will be skipped.
941
+ */
942
+ disableAll(persist?: boolean): void;
943
+ /**
944
+ * Rebuild the logging methods on this logger and its child loggers.
945
+ *
946
+ * This is mostly intended for plugin developers, but can be useful if you update a logger's `methodFactory` or
947
+ * if you want to apply the root logger’s level to any *pre-existing* child loggers (this updates the level on
948
+ * any child logger that hasn't used `setLevel()` or `setDefaultLevel()`).
949
+ */
950
+ rebuild(): void;
951
+ }
952
+ export interface OutputConfiguration {
953
+ writeOut?(str: string): void;
954
+ writeErr?(str: string): void;
955
+ outputError?(str: string, write: (str: string) => void): void;
956
+ getOutHelpWidth?(): number;
957
+ getErrHelpWidth?(): number;
958
+ getOutHasColors?(): boolean;
959
+ getErrHasColors?(): boolean;
960
+ stripColor?(str: string): string;
961
+ }
962
+ export interface Package {
963
+ name: string;
964
+ localName: string;
965
+ scripts: Record<string, string>;
966
+ path: string;
967
+ pkgJson: PackageJson;
968
+ }
969
+ export interface PackageJson extends Record<string, unknown> {
970
+ workspaces?: string[];
971
+ name: string;
972
+ version: string;
973
+ scripts?: Record<string, string>;
974
+ files?: string[];
975
+ }
976
+ export interface ParseOptions {
977
+ from: "node" | "electron" | "user";
978
+ }
979
+ export interface ParseOptionsResult {
980
+ operands: string[];
981
+ unknown: string[];
982
+ }
983
+ export interface ProcessInput {
984
+ name: string;
985
+ value: boolean | string;
986
+ }
987
+ export interface Program extends Command {
988
+ rootPath: string;
989
+ logger: typeof logger;
990
+ defineCommand(command: AbstractCommand): void;
991
+ getCommands(): Array<AbstractCommand>;
992
+ getPluginPaths(): Promise<Array<{
993
+ path: string;
994
+ pkgJson: PackageJson;
995
+ }>>;
996
+ }
997
+ export type AddHelpTextPosition = "beforeAll" | "before" | "after" | "afterAll";
998
+ export type HelpConfiguration = Partial<Help>;
999
+ export type HookEvent = "preSubcommand" | "preAction" | "postAction";
1000
+ export type Id = `${string}-${string}-${string}-${string}-${string}`;
1001
+ // Type definitions for commander
1002
+ // 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>
1003
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1004
+ // This is a trick to encourage editor to suggest the known literals while still
1005
+ // allowing any BaseType value.
1006
+ // References:
1007
+ // - https://github.com/microsoft/TypeScript/issues/29729
1008
+ // - https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts
1009
+ // - https://github.com/sindresorhus/type-fest/blob/main/source/primitive.d.ts
1010
+ export type LiteralUnion<LiteralType, BaseType extends string | number> = LiteralType | (BaseType & Record<never, never>);
1011
+ export type LogLevelDesc = LogLevelNumbers | LogLevelNames | "silent" | keyof LogLevel;
1012
+ export type LogLevelNames = "trace" | "debug" | "info" | "warn" | "error";
1013
+ export type LogLevelNumbers = LogLevel[keyof LogLevel];
1014
+ export type LoggingMethod = (...message: any[]) => void;
1015
+ export type MethodFactory = (methodName: LogLevelNames, level: LogLevelNumbers, loggerName: string | symbol) => LoggingMethod;
1016
+ // The source is a string so author can define their own too.
1017
+ export type OptionValueSource = LiteralUnion<"default" | "config" | "env" | "cli" | "implied", string> | undefined;
1018
+ export type OptionValues = Record<string, any>;
1019
+ interface ErrorOptions$1 {
1020
+ // optional parameter for error()
1021
+ /** an id string representing the error */
1022
+ code?: string;
1023
+ /** suggested exit code which could be used with process.exit */
1024
+ exitCode?: number;
1025
+ }
1026
+
1027
+ declare namespace FoxfordTools {
1028
+ export { Package, PackageJson, ProcessInput, Program };
1029
+ }
1030
+
1031
+ export {};