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

1// Type definitions for commander2// 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 */56// This is a trick to encourage editor to suggest the known literals while still7// 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.ts12type LiteralUnion<LiteralType, BaseType extends string | number> =13  | LiteralType14  | (BaseType & Record<never, never>);1516export 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 name3940export interface ErrorOptions {41  // optional parameter for error()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;52  defaultValue?: any;53  defaultValueDescription?: string;54  parseArg?: <T>(value: string, previous: T) => T;55  argChoices?: string[];5657  /**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;108  presetArg?: unknown;109  envVar?: string;110  parseArg?: <T>(value: string, previous: T) => T;111  hidden: boolean;112  argChoices?: string[];113  helpGroupHeading?: string;114115  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 used193   * as an object attribute key.194   */195  attributeName(): string;196197  /**198   * Set the help group heading.199   */200  helpGroup(heading: string): this;201202  /**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;213  minWidthToWrap: number;214  sortSubcommands: boolean;215  sortOptions: boolean;216  showGlobalOptions: boolean;217218  constructor();219220  /*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;231232  /** 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[];254  /** Get an array of the visible global options. (Not including help.) */255  visibleGlobalOptions(cmd: Command): Option[];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;263  /** Get the longest global option term length. */264  longestGlobalOptionTermLength(cmd: Command, helper: Help): number;265  /** Get the longest argument term length. */266  longestArgumentTermLength(cmd: Command, helper: Help): number;267268  /** 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;280  styleOptionDescription(str: string): string;281  styleSubcommandDescription(str: string): string;282  styleArgumentDescription(str: string): string;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;296297  /** Calculate the pad width from the maximum term length. */298  padWidth(cmd: Command, helper: Help): number;299300  /**301   * Wrap a string at whitespace, preserving existing line breaks.302   * Wrapping is skipped if the width is less than `minWidthToWrap`.303   */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,321  ): string;322323  /**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[]>;336337  /** 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}345export interface HelpContext {346  // optional parameter for .help() and .outputHelp()347  error: boolean;348}349export interface AddHelpTextContext {350  // passed to text function used with .addHelpText()351  error: boolean;352  command: Command;353}354export interface OutputConfiguration {355  writeOut?(str: string): void;356  writeErr?(str: string): void;357  outputError?(str: string, write: (str: string) => void): void;358359  getOutHelpWidth?(): number;360  getErrHelpWidth?(): number;361362  getOutHasColors?(): boolean;363  getErrHasColors?(): boolean;364  stripColor?(str: string): string;365}366367export type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';368export type HookEvent = 'preSubcommand' | 'preAction' | 'postAction';369// The source is a string so author can define their own too.370export type OptionValueSource =371  | LiteralUnion<'default' | 'config' | 'env' | 'cli' | 'implied', string>372  | undefined;373374export type OptionValues = Record<string, any>;375376export class Command {377  args: string[];378  processedArgs: any[];379  readonly commands: readonly Command[];380  readonly options: readonly Option[];381  readonly registeredArguments: readonly Argument[];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   */394  version(str: string, flags?: string, description?: string): this;395  /**396   * Get the program version.397   */398  version(): string | undefined;399400  /**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   */420  command(421    nameAndArgs: string,422    opts?: CommandOptions,423  ): ReturnType<this['createCommand']>;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   */442  command(443    nameAndArgs: string,444    description: string,445    opts?: ExecutableCommandOptions,446  ): this;447448  /**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   */487  argument<T>(488    flags: string,489    description: string,490    parseArg: (value: string, previous: T) => T,491    defaultValue?: T,492  ): this;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  /**517   * Customise or override default help command. By default a help command is automatically added if your command has subcommands.518   *519   * @example520   * ```ts521   * 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 subcommands525   * ```526   */527  helpCommand(nameAndArgs: string, description?: string): this;528  helpCommand(enable: boolean): this;529530  /**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  /**540   * Add hook for life cycle event.541   */542  hook(543    event: HookEvent,544    listener: (545      thisCommand: Command,546      actionCommand: Command,547    ) => void | Promise<void>,548  ): this;549550  /**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   */626  action(fn: (this: this, ...args: any[]) => void | Promise<void>): this;627628  /**629   * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.630   *631   * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required632   * option-argument is indicated by `<>` and an optional option-argument by `[]`.633   *634   * See the README for more details, and see also addOption() and requiredOption().635   *636   * @example637   *638   * ```js639   * program640   *     .option('-p, --pepper', 'add pepper')641   *     .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument642   *     .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default643   *     .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function644   * ```645   *646   * @returns `this` command for chaining647   */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;659  /** @deprecated since v7, instead use choices or a custom function */660  option(661    flags: string,662    description: string,663    regexp: RegExp,664    defaultValue?: string | boolean | string[],665  ): this;666667  /**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   */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;684  /** @deprecated since v7, instead use choices or a custom function */685  requiredOption(686    flags: string,687    description: string,688    regexp: RegExp,689    defaultValue?: string | boolean | string[],690  ): this;691692  /**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;715  storeOptionsAsProperties<T extends OptionValues>(716    storeAsProperties: true,717  ): this & T;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   */733  setOptionValueWithSource(734    key: string,735    value: unknown,736    source: OptionValueSource,737  ): this;738739  /**740   * Get source of option value.741   */742  getOptionValueSource(key: string): OptionValueSource | undefined;743744  /**745   * Get source of option value. See also .optsWithGlobals().746   */747  getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined;748749  /**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   *801   * Use parseAsync instead of parse if any of your action handlers are async.802   *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   *810   * @example811   * ```812   * program.parse(); // parse process.argv and auto-detect electron and special node flags813   * program.parse(process.argv); // assume argv[0] is app and argv[1] is script814   * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]815   * ```816   *817   * @returns `this` command for chaining818   */819  parse(argv?: readonly string[], parseOptions?: ParseOptions): this;820821  /**822   * Parse `argv`, setting options and invoking commands when defined.823   *824   * Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!825   *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 arguments830   *831   * @example832   * ```833   * await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags834   * 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]836   * ```837   *838   * @returns Promise839   */840  parseAsync(841    argv?: readonly string[],842    parseOptions?: ParseOptions,843  ): Promise<this>;844845  /**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  /**862   * Parse options from `argv` removing known options,863   * and return argv split into operands and unknown arguments.864   *865   * Side effects: modifies command by storing options. Does not reset state if called again.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 */893  description(str: string, argsDescription: Record<string, string>): this;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],961   * or import.meta.filename.962   *963   * (Used internally and public although not documented in README.)964   *965   * @example966   * ```ts967   * program.nameFromFilename(import.meta.filename);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   * ```ts979   * program.executableDir(import.meta.dirname);980   * // or981   * program.executableDir('subcommands');982   * ```983   *984   * @returns `this` command for chaining985   */986  executableDir(path: string): this;987  /**988   * Get the executable search directory.989   */990  executableDir(): string | null;991992  /**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;10381039  /**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 */1047  outputHelp(cb: (str: string) => string): void;10481049  /**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;10601061  /**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;10661067  /**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 */1074  help(cb: (str: string) => string): never;10751076  /**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;1083  addHelpText(1084    position: AddHelpTextPosition,1085    text: (context: AddHelpTextContext) => string,1086  ): this;10871088  /**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;