Skip to content
Myr

index.d.ts

This file

Path

typings/index.d.ts

1,113 lines · 33.9 KiB · TypeScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take it

The walk stopped after 200 commits: lines older than 471ec40 point at it.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 1–5why, one step back
1// Type definitions for commander
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>34/* eslint-disable @typescript-eslint/no-explicit-any */5

Make OptionValueSource a string with well-known values for auto-complete. (#1983)John Geebefore adoption0d432ba

lines 6–11why, one step back
6// This is a trick to encourage editor to suggest the known literals while still
7// allowing any BaseType value.8// References:9// - https://github.com/microsoft/TypeScript/issues/2972910// - https://github.com/sindresorhus/type-fest/blob/main/source/literal-union.d.ts11// - https://github.com/sindresorhus/type-fest/blob/main/source/primitive.d.ts

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 12–14why, one step back
12type LiteralUnion<LiteralType, BaseType extends string | number> =
13 | LiteralType14 | (BaseType & Record<never, never>);

Make OptionValueSource a string with well-known values for auto-complete. (#1983)John Geebefore adoption0d432ba

line 15why, one step back
15

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 16–39why, one step back
16export class CommanderError extends Error {
17 code: string;18 exitCode: number;19 message: string;20 nestedError?: string;2122 /**23 * Constructs the CommanderError class24 * @param exitCode - suggested exit code which could be used with process.exit25 * @param code - an id string representing the error26 * @param message - human-readable description of the error27 */28 constructor(exitCode: number, code: string, message: string);29}3031export class InvalidArgumentError extends CommanderError {32 /**33 * Constructs the InvalidArgumentError class34 * @param message - explanation of why argument is invalid35 */36 constructor(message: string);37}38export { InvalidArgumentError as InvalidOptionArgumentError }; // deprecated old name39

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 40–41why, one step back
40export interface ErrorOptions {
41 // optional parameter for error()

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 42–51why, one step back
42 /** an id string representing the error */
43 code?: string;44 /** suggested exit code which could be used with process.exit */45 exitCode?: number;46}4748export class Argument {49 description: string;50 required: boolean;51 variadic: boolean;

Add more Option and Argument properties to typings (#2019)John Geebefore adoption744ee3f

lines 52–53why, one step back
52 defaultValue?: any;
53 defaultValueDescription?: string;

Merge branch 'develop' into release/14.xJohn Geebefore adoption00af603

line 54why, one step back
54 parseArg?: <T>(value: string, previous: T) => T;

Add more Option and Argument properties to typings (#2019)John Geebefore adoption744ee3f

line 55why, one step back
55 argChoices?: string[];

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 56–107why, one step back
56
57 /**58 * Initialize a new command argument with the given name and description.59 * The default is that the argument is required, and you can explicitly60 * indicate this with <> around the name. Put [] around the name for an optional argument.61 */62 constructor(arg: string, description?: string);6364 /**65 * Return argument name.66 */67 name(): string;6869 /**70 * Set the default value, and optionally supply the description to be displayed in the help.71 */72 default(value: unknown, description?: string): this;7374 /**75 * Set the custom handler for processing CLI command arguments into argument values.76 */77 argParser<T>(fn: (value: string, previous: T) => T): this;7879 /**80 * Only allow argument value to be one of choices.81 */82 choices(values: readonly string[]): this;8384 /**85 * Make argument required.86 */87 argRequired(): this;8889 /**90 * Make argument optional.91 */92 argOptional(): this;93}9495export class Option {96 flags: string;97 description: string;9899 required: boolean; // A value must be supplied when the option is specified.100 optional: boolean; // A value is optional when the option is specified.101 variadic: boolean;102 mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line.103 short?: string;104 long?: string;105 negate: boolean;106 defaultValue?: any;107 defaultValueDescription?: string;

Add more Option and Argument properties to typings (#2019)John Geebefore adoption744ee3f

lines 108–109why, one step back
108 presetArg?: unknown;
109 envVar?: string;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 110–112why, one step back
110 parseArg?: <T>(value: string, previous: T) => T;
111 hidden: boolean;112 argChoices?: string[];

Add typings for helpGroup support (#2367)John Geebefore adoptiondd7edf4

line 113why, one step back
113 helpGroupHeading?: string;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 114–192why, one step back
114
115 constructor(flags: string, description?: string);116117 /**118 * Set the default value, and optionally supply the description to be displayed in the help.119 */120 default(value: unknown, description?: string): this;121122 /**123 * Preset to use when option used without option-argument, especially optional but also boolean and negated.124 * The custom processing (parseArg) is called.125 *126 * @example127 * ```ts128 * new Option('--color').default('GREYSCALE').preset('RGB');129 * new Option('--donate [amount]').preset('20').argParser(parseFloat);130 * ```131 */132 preset(arg: unknown): this;133134 /**135 * Add option name(s) that conflict with this option.136 * An error will be displayed if conflicting options are found during parsing.137 *138 * @example139 * ```ts140 * new Option('--rgb').conflicts('cmyk');141 * new Option('--js').conflicts(['ts', 'jsx']);142 * ```143 */144 conflicts(names: string | string[]): this;145146 /**147 * Specify implied option values for when this option is set and the implied options are not.148 *149 * The custom processing (parseArg) is not called on the implied values.150 *151 * @example152 * program153 * .addOption(new Option('--log', 'write logging information to file'))154 * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));155 */156 implies(optionValues: OptionValues): this;157158 /**159 * Set environment variable to check for option value.160 *161 * An environment variables is only used if when processed the current option value is162 * undefined, or the source of the current value is 'default' or 'config' or 'env'.163 */164 env(name: string): this;165166 /**167 * Set the custom handler for processing CLI option arguments into option values.168 */169 argParser<T>(fn: (value: string, previous: T) => T): this;170171 /**172 * Whether the option is mandatory and must have a value after parsing.173 */174 makeOptionMandatory(mandatory?: boolean): this;175176 /**177 * Hide option in help.178 */179 hideHelp(hide?: boolean): this;180181 /**182 * Only allow option value to be one of choices.183 */184 choices(values: readonly string[]): this;185186 /**187 * Return option name.188 */189 name(): string;190191 /**192 * Return option name, in a camelcase format that can be used

Merge branch 'develop' into release/13.xJohn Geebefore adoption5a79585

line 193why, one step back
193 * as an object attribute key.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 194–197why, one step back
194 */
195 attributeName(): string;196197 /**

Add typings for helpGroup support (#2367)John Geebefore adoptiondd7edf4

lines 198–202why, one step back
198 * Set the help group heading.
199 */200 helpGroup(heading: string): this;201202 /**

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 203–212why, one step back
203 * Return whether a boolean option.
204 *205 * Options are one of boolean, negated, required argument, or optional argument.206 */207 isBoolean(): boolean;208}209210export class Help {211 /** output helpWidth, long lines are wrapped to fit */212 helpWidth?: number;

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

line 213why, one step back
213 minWidthToWrap: number;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 214–215why, one step back
214 sortSubcommands: boolean;
215 sortOptions: boolean;

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

line 216why, one step back
216 showGlobalOptions: boolean;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 217–219why, one step back
217
218 constructor();219

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 220–231why, one step back
220 /*
221 * prepareContext is called by Commander after applying overrides from `Command.configureHelp()`222 * and just before calling `formatHelp()`.223 *224 * Commander just uses the helpWidth and the others are provided for subclasses.225 */226 prepareContext(contextOptions: {227 error?: boolean;228 helpWidth?: number;229 outputHasColors?: boolean;230 }): void;231

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 232–253why, one step back
232 /** Get the command term to show in the list of subcommands. */
233 subcommandTerm(cmd: Command): string;234 /** Get the command summary to show in the list of subcommands. */235 subcommandDescription(cmd: Command): string;236 /** Get the option term to show in the list of options. */237 optionTerm(option: Option): string;238 /** Get the option description to show in the list of options. */239 optionDescription(option: Option): string;240 /** Get the argument term to show in the list of arguments. */241 argumentTerm(argument: Argument): string;242 /** Get the argument description to show in the list of arguments. */243 argumentDescription(argument: Argument): string;244245 /** Get the command usage to be displayed at the top of the built-in help. */246 commandUsage(cmd: Command): string;247 /** Get the description for the command. */248 commandDescription(cmd: Command): string;249250 /** Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one. */251 visibleCommands(cmd: Command): Command[];252 /** Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one. */253 visibleOptions(cmd: Command): Option[];

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 254–255why, one step back
254 /** Get an array of the visible global options. (Not including help.) */
255 visibleGlobalOptions(cmd: Command): Option[];

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 256–262why, one step back
256 /** Get an array of the arguments which have descriptions. */
257 visibleArguments(cmd: Command): Argument[];258259 /** Get the longest command term length. */260 longestSubcommandTermLength(cmd: Command, helper: Help): number;261 /** Get the longest option term length. */262 longestOptionTermLength(cmd: Command, helper: Help): number;

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 263–264why, one step back
263 /** Get the longest global option term length. */
264 longestGlobalOptionTermLength(cmd: Command, helper: Help): number;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 265–266why, one step back
265 /** Get the longest argument term length. */
266 longestArgumentTermLength(cmd: Command, helper: Help): number;

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 267–279why, one step back
267
268 /** Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations. */269 displayWidth(str: string): number;270271 /** Style the titles. Called with 'Usage:', 'Options:', etc. */272 styleTitle(title: string): string;273274 /** Usage: <str> */275 styleUsage(str: string): string;276 /** Style for command name in usage string. */277 styleCommandText(str: string): string;278279 styleCommandDescription(str: string): string;

Split styleItemDescription into option/subcommand/argument (#2283)John Geebefore adoption437e4e3

lines 280–282why, one step back
280 styleOptionDescription(str: string): string;
281 styleSubcommandDescription(str: string): string;282 styleArgumentDescription(str: string): string;

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 283–296why, one step back
283 /** Base style used by descriptions. */
284 styleDescriptionText(str: string): string;285286 styleOptionTerm(str: string): string;287 styleSubcommandTerm(str: string): string;288 styleArgumentTerm(str: string): string;289290 /** Base style used in terms and usage for options. */291 styleOptionText(str: string): string;292 /** Base style used in terms and usage for subcommands. */293 styleSubcommandText(str: string): string;294 /** Base style used in terms and usage for arguments. */295 styleArgumentText(str: string): string;296

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 297–300why, one step back
297 /** Calculate the pad width from the maximum term length. */
298 padWidth(cmd: Command, helper: Help): number;299300 /**

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 301–302why, one step back
301 * Wrap a string at whitespace, preserving existing line breaks.
302 * Wrapping is skipped if the width is less than `minWidthToWrap`.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 303why, one step back
303 */

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 304–320why, one step back
304 boxWrap(str: string, width: number): string;
305306 /** Detect manually wrapped and indented strings by checking for line break followed by whitespace. */307 preformatted(str: string): boolean;308309 /**310 * Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.311 *312 * So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:313 * TTT DDD DDDD314 * DD DDD315 */316 formatItem(317 term: string,318 termWidth: number,319 description: string,320 helper: Help,

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 321why, one step back
321 ): string;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 322why, one step back
322

Add typings for helpGroup support (#2367)John Geebefore adoptiondd7edf4

lines 323–336why, one step back
323 /**
324 * Format a list of items, given a heading and an array of formatted items.325 */326 formatItemList(heading: string, items: string[], helper: Help): string[];327328 /**329 * Group items by their help group heading.330 */331 groupItems<T extends Command | Option>(332 unsortedItems: T[],333 visibleItems: T[],334 getGroup: (item: T) => string,335 ): Map<string, T[]>;336

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 337–344why, one step back
337 /** Generate the built-in help text. */
338 formatHelp(cmd: Command, helper: Help): string;339}340export type HelpConfiguration = Partial<Help>;341342export interface ParseOptions {343 from: 'node' | 'electron' | 'user';344}

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 345–346why, one step back
345export interface HelpContext {
346 // optional parameter for .help() and .outputHelp()

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 347–348why, one step back
347 error: boolean;
348}

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 349–350why, one step back
349export interface AddHelpTextContext {
350 // passed to text function used with .addHelpText()

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 351–356why, one step back
351 error: boolean;
352 command: Command;353}354export interface OutputConfiguration {355 writeOut?(str: string): void;356 writeErr?(str: string): void;

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 357–358why, one step back
357 outputError?(str: string, write: (str: string) => void): void;
358

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 359–360why, one step back
359 getOutHelpWidth?(): number;
360 getErrHelpWidth?(): number;

Support color ansi code sequences in custom help (#2251)John Geebefore adoption5629947

lines 361–364why, one step back
361
362 getOutHasColors?(): boolean;363 getErrHasColors?(): boolean;364 stripColor?(str: string): string;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 365–368why, one step back
365}
366367export type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';368export type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';

Make OptionValueSource a string with well-known values for auto-complete. (#1983)John Geebefore adoption0d432ba

line 369why, one step back
369// The source is a string so author can define their own too.

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 370–372why, one step back
370export type OptionValueSource =
371 | LiteralUnion<'default' | 'config' | 'env' | 'cli' | 'implied', string>372 | undefined;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 373why, one step back
373

*: update dev deps and make tweaksMohammed Keyvanzadehbefore adoption5f3f004

line 374why, one step back
374export type OptionValues = Record<string, any>;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 375–378why, one step back
375
376export class Command {377 args: string[];378 processedArgs: any[];

Add Command.options to TypeScript (#1827)John Geebefore adoption04fc0fd

lines 379–380why, one step back
379 readonly commands: readonly Command[];
380 readonly options: readonly Option[];

Add public Arguments property (#2010)John Geebefore adoption7d23437

line 381why, one step back
381 readonly registeredArguments: readonly Argument[];

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 382–393why, one step back
382 parent: Command | null;
383384 constructor(name?: string);385386 /**387 * Set the program version to `str`.388 *389 * This method auto-registers the "-V, --version" flag390 * which will print the version number when passed.391 *392 * You can optionally supply the flags and description to override the defaults.393 */

Revert "Fix version() parameter type"Wee Bitbefore adoptionf3431d1

line 394why, one step back
394 version(str: string, flags?: string, description?: string): this;

Types for version getter (#1982)John Geebefore adoptionf5413db

lines 395–398why, one step back
395 /**
396 * Get the program version.397 */398 version(): string | undefined;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 399–419why, one step back
399
400 /**401 * Define a command, implemented using an action handler.402 *403 * @remarks404 * The command description is supplied using `.description`, not as a parameter to `.command`.405 *406 * @example407 * ```ts408 * program409 * .command('clone <source> [destination]')410 * .description('clone a repository into a newly created directory')411 * .action((source, destination) => {412 * console.log('clone command called');413 * });414 * ```415 *416 * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`417 * @param opts - configuration options418 * @returns new command419 */

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 420–423why, one step back
420 command(
421 nameAndArgs: string,422 opts?: CommandOptions,423 ): ReturnType<this['createCommand']>;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 424–441why, one step back
424 /**
425 * Define a command, implemented in a separate executable file.426 *427 * @remarks428 * The command description is supplied as the second parameter to `.command`.429 *430 * @example431 * ```ts432 * program433 * .command('start <service>', 'start named service')434 * .command('stop [service]', 'stop named service, or all if no name supplied');435 * ```436 *437 * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`438 * @param description - description of executable command439 * @param opts - configuration options440 * @returns `this` command for chaining441 */

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 442–446why, one step back
442 command(
443 nameAndArgs: string,444 description: string,445 opts?: ExecutableCommandOptions,446 ): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 447–486why, one step back
447
448 /**449 * Factory routine to create a new unattached command.450 *451 * See .command() for creating an attached subcommand, which uses this routine to452 * create the command. You can override createCommand to customise subcommands.453 */454 createCommand(name?: string): Command;455456 /**457 * Add a prepared subcommand.458 *459 * See .command() for creating an attached subcommand which inherits settings from its parent.460 *461 * @returns `this` command for chaining462 */463 addCommand(cmd: Command, opts?: CommandOptions): this;464465 /**466 * Factory routine to create a new unattached argument.467 *468 * See .argument() for creating an attached argument, which uses this routine to469 * create the argument. You can override createArgument to return a custom argument.470 */471 createArgument(name: string, description?: string): Argument;472473 /**474 * Define argument syntax for command.475 *476 * The default is that the argument is required, and you can explicitly477 * indicate this with <> around the name. Put [] around the name for an optional argument.478 *479 * @example480 * ```481 * program.argument('<input-file>');482 * program.argument('[output-file]');483 * ```484 *485 * @returns `this` command for chaining486 */

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 487–489why, one step back
487 argument<T>(
488 flags: string,489 description: string,

Merge branch 'develop' into release/14.xJohn Geebefore adoption00af603

line 490why, one step back
490 parseArg: (value: string, previous: T) => T,

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 491–492why, one step back
491 defaultValue?: T,
492 ): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 493–516why, one step back
493 argument(name: string, description?: string, defaultValue?: unknown): this;
494495 /**496 * Define argument syntax for command, adding a prepared argument.497 *498 * @returns `this` command for chaining499 */500 addArgument(arg: Argument): this;501502 /**503 * Define argument syntax for command, adding multiple at once (without descriptions).504 *505 * See also .argument().506 *507 * @example508 * ```509 * program.arguments('<cmd> [env]');510 * ```511 *512 * @returns `this` command for chaining513 */514 arguments(names: string): this;515516 /**

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 517why, one step back
517 * Customise or override default help command. By default a help command is automatically added if your command has subcommands.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 518–519why, one step back
518 *
519 * @example

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 520–524why, one step back
520 * ```ts
521 * program.helpCommand('help [cmd]');522 * program.helpCommand('help [cmd]', 'show help');523 * program.helpCommand(false); // suppress default help command524 * program.helpCommand(true); // add help command even if no subcommands

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 525–526why, one step back
525 * ```
526 */

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 527–528why, one step back
527 helpCommand(nameAndArgs: string, description?: string): this;
528 helpCommand(enable: boolean): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 529–530why, one step back
529
530 /**

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 531–539why, one step back
531 * Add prepared custom help command.
532 */533 addHelpCommand(cmd: Command): this;534 /** @deprecated since v12, instead use helpCommand */535 addHelpCommand(nameAndArgs: string, description?: string): this;536 /** @deprecated since v12, instead use helpCommand */537 addHelpCommand(enable?: boolean): this;538539 /**

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 540–541why, one step back
540 * Add hook for life cycle event.
541 */

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 542–548why, one step back
542 hook(
543 event: HookEvent,544 listener: (545 thisCommand: Command,546 actionCommand: Command,547 ) => void | Promise<void>,548 ): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 549–625why, one step back
549
550 /**551 * Register callback to use as replacement for calling process.exit.552 */553 exitOverride(callback?: (err: CommanderError) => never | void): this;554555 /**556 * Display error message and exit (or call exitOverride).557 */558 error(message: string, errorOptions?: ErrorOptions): never;559560 /**561 * You can customise the help with a subclass of Help by overriding createHelp,562 * or by overriding Help properties using configureHelp().563 */564 createHelp(): Help;565566 /**567 * You can customise the help by overriding Help properties using configureHelp(),568 * or with a subclass of Help by overriding createHelp().569 */570 configureHelp(configuration: HelpConfiguration): this;571 /** Get configuration */572 configureHelp(): HelpConfiguration;573574 /**575 * The default output goes to stdout and stderr. You can customise this for special576 * applications. You can also customise the display of errors by overriding outputError.577 *578 * The configuration properties are all functions:579 * ```580 * // functions to change where being written, stdout and stderr581 * writeOut(str)582 * writeErr(str)583 * // matching functions to specify width for wrapping help584 * getOutHelpWidth()585 * getErrHelpWidth()586 * // functions based on what is being written out587 * outputError(str, write) // used for displaying errors, and not used for displaying help588 * ```589 */590 configureOutput(configuration: OutputConfiguration): this;591 /** Get configuration */592 configureOutput(): OutputConfiguration;593594 /**595 * Copy settings that are useful to have in common across root command and subcommands.596 *597 * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)598 */599 copyInheritedSettings(sourceCommand: Command): this;600601 /**602 * Display the help or a custom message after an error occurs.603 */604 showHelpAfterError(displayHelp?: boolean | string): this;605606 /**607 * Display suggestion of similar commands for unknown commands, or options for unknown options.608 */609 showSuggestionAfterError(displaySuggestion?: boolean): this;610611 /**612 * Register callback `fn` for the command.613 *614 * @example615 * ```616 * program617 * .command('serve')618 * .description('start service')619 * .action(function() {620 * // do work here621 * });622 * ```623 *624 * @returns `this` command for chaining625 */

set `this`context (#2197)Matthias Kecklbefore adoption22239e6

line 626why, one step back
626 action(fn: (this: this, ...args: any[]) => void | Promise<void>): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 627–628why, one step back
627
628 /**

Rework option inline doc (#2009)John Geebefore adoptione85e05a

line 629why, one step back
629 * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 630why, one step back
630 *

Rework option inline doc (#2009)John Geebefore adoptione85e05a

lines 631–632why, one step back
631 * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
632 * option-argument is indicated by `<>` and an optional option-argument by `[]`.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 633why, one step back
633 *

Rework option inline doc (#2009)John Geebefore adoptione85e05a

line 634why, one step back
634 * See the README for more details, and see also addOption() and requiredOption().

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 635–637why, one step back
635 *
636 * @example637 *

Rework option inline doc (#2009)John Geebefore adoptione85e05a

lines 638–640why, one step back
638 * ```js
639 * program640 * .option('-p, --pepper', 'add pepper')

Add support for dual long options when no short option (#2312)John Geebefore adoption8263b7f

line 641why, one step back
641 * .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument

Rework option inline doc (#2009)John Geebefore adoptione85e05a

lines 642–643why, one step back
642 * .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
643 * .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 644–647why, one step back
644 * ```
645 *646 * @returns `this` command for chaining647 */

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 648–658why, one step back
648 option(
649 flags: string,650 description?: string,651 defaultValue?: string | boolean | string[],652 ): this;653 option<T>(654 flags: string,655 description: string,656 parseArg: (value: string, previous: T) => T,657 defaultValue?: T,658 ): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 659why, one step back
659 /** @deprecated since v7, instead use choices or a custom function */

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 660–665why, one step back
660 option(
661 flags: string,662 description: string,663 regexp: RegExp,664 defaultValue?: string | boolean | string[],665 ): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 666–672why, one step back
666
667 /**668 * Define a required option, which must have a value after parsing. This usually means669 * the option must be specified on the command line. (Otherwise the same as .option().)670 *671 * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.672 */

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 673–683why, one step back
673 requiredOption(
674 flags: string,675 description?: string,676 defaultValue?: string | boolean | string[],677 ): this;678 requiredOption<T>(679 flags: string,680 description: string,681 parseArg: (value: string, previous: T) => T,682 defaultValue?: T,683 ): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 684why, one step back
684 /** @deprecated since v7, instead use choices or a custom function */

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 685–690why, one step back
685 requiredOption(
686 flags: string,687 description: string,688 regexp: RegExp,689 defaultValue?: string | boolean | string[],690 ): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 691–714why, one step back
691
692 /**693 * Factory routine to create a new unattached option.694 *695 * See .option() for creating an attached option, which uses this routine to696 * create the option. You can override createOption to return a custom option.697 */698699 createOption(flags: string, description?: string): Option;700701 /**702 * Add a prepared Option.703 *704 * See .option() and .requiredOption() for creating and attaching an option in a single call.705 */706 addOption(option: Option): this;707708 /**709 * Whether to store option values as properties on command object,710 * or store separately (specify false). In both cases the option values can be accessed using .opts().711 *712 * @returns `this` command for chaining713 */714 storeOptionsAsProperties<T extends OptionValues>(): this & T;

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 715–717why, one step back
715 storeOptionsAsProperties<T extends OptionValues>(
716 storeAsProperties: true,717 ): this & T;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 718–732why, one step back
718 storeOptionsAsProperties(storeAsProperties?: boolean): this;
719720 /**721 * Retrieve option value.722 */723 getOptionValue(key: string): any;724725 /**726 * Store option value.727 */728 setOptionValue(key: string, value: unknown): this;729730 /**731 * Store option value and where the value came from.732 */

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 733–737why, one step back
733 setOptionValueWithSource(
734 key: string,735 value: unknown,736 source: OptionValueSource,737 ): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 738–739why, one step back
738
739 /**

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

line 740why, one step back
740 * Get source of option value.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 741–742why, one step back
741 */
742 getOptionValueSource(key: string): OptionValueSource | undefined;

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 743–744why, one step back
743
744 /**

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 745why, one step back
745 * Get source of option value. See also .optsWithGlobals().

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 746–747why, one step back
746 */
747 getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 748–800why, one step back
748
749 /**750 * Alter parsing of short flags with optional values.751 *752 * @example753 * ```754 * // for `.option('-f,--flag [value]'):755 * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour756 * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`757 * ```758 *759 * @returns `this` command for chaining760 */761 combineFlagAndOptionalValue(combine?: boolean): this;762763 /**764 * Allow unknown options on the command line.765 *766 * @returns `this` command for chaining767 */768 allowUnknownOption(allowUnknown?: boolean): this;769770 /**771 * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.772 *773 * @returns `this` command for chaining774 */775 allowExcessArguments(allowExcess?: boolean): this;776777 /**778 * Enable positional options. Positional means global options are specified before subcommands which lets779 * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.780 *781 * The default behaviour is non-positional and global options may appear anywhere on the command line.782 *783 * @returns `this` command for chaining784 */785 enablePositionalOptions(positional?: boolean): this;786787 /**788 * Pass through options that come after command-arguments rather than treat them as command-options,789 * so actual command-options come before command-arguments. Turning this on for a subcommand requires790 * positional options to have been enabled on the program (parent commands).791 *792 * The default behaviour is non-positional and options may appear before or after command-arguments.793 *794 * @returns `this` command for chaining795 */796 passThroughOptions(passThrough?: boolean): this;797798 /**799 * Parse `argv`, setting options and invoking commands when defined.800 *

Add auto-detection of args when node evaluating script code on command-line (#2164)John Geebefore adoptionb9ca390

line 801why, one step back
801 * Use parseAsync instead of parse if any of your action handlers are async.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 802why, one step back
802 *

Add auto-detection of args when node evaluating script code on command-line (#2164)John Geebefore adoptionb9ca390

lines 803–809why, one step back
803 * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
804 *805 * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:806 * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that807 * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged808 * - `'user'`: just user arguments809 *

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 810–811why, one step back
810 * @example
811 * ```

Add auto-detection of args when node evaluating script code on command-line (#2164)John Geebefore adoptionb9ca390

lines 812–813why, one step back
812 * program.parse(); // parse process.argv and auto-detect electron and special node flags
813 * program.parse(process.argv); // assume argv[0] is app and argv[1] is script

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 814–818why, one step back
814 * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
815 * ```816 *817 * @returns `this` command for chaining818 */

Add auto-detection of args when node evaluating script code on command-line (#2164)John Geebefore adoptionb9ca390

line 819why, one step back
819 parse(argv?: readonly string[], parseOptions?: ParseOptions): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 820–823why, one step back
820
821 /**822 * Parse `argv`, setting options and invoking commands when defined.823 *

Add auto-detection of args when node evaluating script code on command-line (#2164)John Geebefore adoptionb9ca390

line 824why, one step back
824 * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 825why, one step back
825 *

Add auto-detection of args when node evaluating script code on command-line (#2164)John Geebefore adoptionb9ca390

lines 826–829why, one step back
826 * Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
827 * - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that828 * - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged829 * - `'user'`: just user arguments

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 830–832why, one step back
830 *
831 * @example832 * ```

Add auto-detection of args when node evaluating script code on command-line (#2164)John Geebefore adoptionb9ca390

lines 833–835why, one step back
833 * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
834 * await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script835 * await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 836–839why, one step back
836 * ```
837 *838 * @returns Promise839 */

Add auto-detection of args when node evaluating script code on command-line (#2164)John Geebefore adoptionb9ca390

lines 840–843why, one step back
840 parseAsync(
841 argv?: readonly string[],842 parseOptions?: ParseOptions,843 ): Promise<this>;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 844–845why, one step back
844
845 /**

Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2

lines 846–861why, one step back
846 * Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
847 * Not usually called directly, but available for subclasses to save their custom state.848 *849 * This is called in a lazy way. Only commands used in parsing chain will have state saved.850 */851 saveStateBeforeParse(): void;852853 /**854 * Restore state before parse for calls after the first.855 * Not usually called directly, but available for subclasses to save their custom state.856 *857 * This is called in a lazy way. Only commands used in parsing chain will have state restored.858 */859 restoreStateBeforeParse(): void;860861 /**

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 862–863why, one step back
862 * Parse options from `argv` removing known options,
863 * and return argv split into operands and unknown arguments.

Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2

lines 864–865why, one step back
864 *
865 * Side effects: modifies command by storing options. Does not reset state if called again.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 866–892why, one step back
866 *
867 * argv => operands, unknown868 * --known kkk op => [op], []869 * op --known kkk => [op], []870 * sub --unknown uuu op => [sub], [--unknown uuu op]871 * sub -- --unknown uuu op => [sub --unknown uuu op], []872 */873 parseOptions(argv: string[]): ParseOptionsResult;874875 /**876 * Return an object containing local option values as key-value pairs877 */878 opts<T extends OptionValues>(): T;879880 /**881 * Return an object containing merged local and global option values as key-value pairs.882 */883 optsWithGlobals<T extends OptionValues>(): T;884885 /**886 * Set the description.887 *888 * @returns `this` command for chaining889 */890891 description(str: string): this;892 /** @deprecated since v8, instead use .argument to add command argument with description */

*: update dev deps and make tweaksMohammed Keyvanzadehbefore adoption5f3f004

line 893why, one step back
893 description(str: string, argsDescription: Record<string, string>): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 894–960why, one step back
894 /**
895 * Get the description.896 */897 description(): string;898899 /**900 * Set the summary. Used when listed as subcommand of parent.901 *902 * @returns `this` command for chaining903 */904905 summary(str: string): this;906 /**907 * Get the summary.908 */909 summary(): string;910911 /**912 * Set an alias for the command.913 *914 * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.915 *916 * @returns `this` command for chaining917 */918 alias(alias: string): this;919 /**920 * Get alias for the command.921 */922 alias(): string;923924 /**925 * Set aliases for the command.926 *927 * Only the first alias is shown in the auto-generated help.928 *929 * @returns `this` command for chaining930 */931 aliases(aliases: readonly string[]): this;932 /**933 * Get aliases for the command.934 */935 aliases(): string[];936937 /**938 * Set the command usage.939 *940 * @returns `this` command for chaining941 */942 usage(str: string): this;943 /**944 * Get the command usage.945 */946 usage(): string;947948 /**949 * Set the name of the command.950 *951 * @returns `this` command for chaining952 */953 name(str: string): this;954 /**955 * Get the name of the command.956 */957 name(): string;958959 /**960 * Set the name of the command from script filename, such as process.argv[1],

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

line 961why, one step back
961 * or import.meta.filename.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 962–966why, one step back
962 *
963 * (Used internally and public although not documented in README.)964 *965 * @example966 * ```ts

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

line 967why, one step back
967 * program.nameFromFilename(import.meta.filename);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 968–978why, one step back
968 * ```
969 *970 * @returns `this` command for chaining971 */972 nameFromFilename(filename: string): this;973974 /**975 * Set the directory for searching for executable subcommands of this command.976 *977 * @example978 * ```ts

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

line 979why, one step back
979 * program.executableDir(import.meta.dirname);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 980–989why, one step back
980 * // or
981 * program.executableDir('subcommands');982 * ```983 *984 * @returns `this` command for chaining985 */986 executableDir(path: string): this;987 /**988 * Get the executable search directory.989 */

Fix executableDir() return typeWee Bitbefore adoption68a4276

line 990why, one step back
990 executableDir(): string | null;

Add typings for helpGroup support (#2367)John Geebefore adoptiondd7edf4

lines 991–1037why, one step back
991
992 /**993 * Set the help group heading for this subcommand in parent command's help.994 *995 * @returns `this` command for chaining996 */997 helpGroup(heading: string): this;998 /**999 * Get the help group heading for this subcommand in parent command's help.1000 */1001 helpGroup(): string;10021003 /**1004 * Set the default help group heading for subcommands added to this command.1005 * (This does not override a group set directly on the subcommand using .helpGroup().)1006 *1007 * @example1008 * program.commandsGroup('Development Commands:);1009 * program.command('watch')...1010 * program.command('lint')...1011 * ...1012 *1013 * @returns `this` command for chaining1014 */1015 commandsGroup(heading: string): this;1016 /**1017 * Get the default help group heading for subcommands added to this command.1018 */1019 commandsGroup(): string;10201021 /**1022 * Set the default help group heading for options added to this command.1023 * (This does not override a group set directly on the option using .helpGroup().)1024 *1025 * @example1026 * program1027 * .optionsGroup('Development Options:')1028 * .option('-d, --debug', 'output extra debugging')1029 * .option('-p, --profile', 'output profiling information')1030 *1031 * @returns `this` command for chaining1032 */1033 optionsGroup(heading: string): this;1034 /**1035 * Get the default help group heading for options added to this command.1036 */1037 optionsGroup(): string;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 1038–1046why, one step back
1038
1039 /**1040 * Output help information for this command.1041 *1042 * Outputs built-in help, and custom text added using `.addHelpText()`.1043 *1044 */1045 outputHelp(context?: HelpContext): void;1046 /** @deprecated since v7 */

Merge from develop (#2482)John Geebefore adoptionb51c0ea

line 1047why, one step back
1047 outputHelp(cb: (str: string) => string): void;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 1048–1059why, one step back
1048
1049 /**1050 * Return command help documentation.1051 */1052 helpInformation(context?: HelpContext): string;10531054 /**1055 * You can pass in flags and a description to override the help1056 * flags and help description for your command. Pass in false1057 * to disable the built-in help option.1058 */1059 helpOption(flags?: string | boolean, description?: string): this;

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 1060–1065why, one step back
1060
1061 /**1062 * Supply your own option to use for the built-in help option.1063 * This is an alternative to using helpOption() to customise the flags and description etc.1064 */1065 addHelpOption(option: Option): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 1066–1073why, one step back
1066
1067 /**1068 * Output help information and exit.1069 *1070 * Outputs built-in help, and custom text added using `.addHelpText()`.1071 */1072 help(context?: HelpContext): never;1073 /** @deprecated since v7 */

Merge from develop (#2482)John Geebefore adoptionb51c0ea

line 1074why, one step back
1074 help(cb: (str: string) => string): never;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 1075–1082why, one step back
1075
1076 /**1077 * Add additional text to be displayed with the built-in help.1078 *1079 * Position is 'before' or 'after' to affect just this command,1080 * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.1081 */1082 addHelpText(position: AddHelpTextPosition, text: string): this;

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 1083–1086why, one step back
1083 addHelpText(
1084 position: AddHelpTextPosition,1085 text: (context: AddHelpTextContext) => string,1086 ): this;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 1087–1113why, one step back
1087
1088 /**1089 * Add a listener (callback) for when events occur. (Implemented using EventEmitter.)1090 */1091 on(event: string | symbol, listener: (...args: any[]) => void): this;1092}10931094export interface CommandOptions {1095 hidden?: boolean;1096 isDefault?: boolean;1097 /** @deprecated since v7, replaced by hidden */1098 noHelp?: boolean;1099}1100export interface ExecutableCommandOptions extends CommandOptions {1101 executableFile?: string;1102}11031104export interface ParseOptionsResult {1105 operands: string[];1106 unknown: string[];1107}11081109export function createCommand(name?: string): Command;1110export function createOption(flags: string, description?: string): Option;1111export function createArgument(name: string, description?: string): Argument;11121113export const program: Command;