index.d.ts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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>
  3. // Using method rather than property for method-signature-style, to document method overloads separately. Allow either.
  4. /* eslint-disable @typescript-eslint/method-signature-style */
  5. /* eslint-disable @typescript-eslint/no-explicit-any */
  6. export class CommanderError extends Error {
  7. code: string;
  8. exitCode: number;
  9. message: string;
  10. nestedError?: string;
  11. /**
  12. * Constructs the CommanderError class
  13. * @param exitCode - suggested exit code which could be used with process.exit
  14. * @param code - an id string representing the error
  15. * @param message - human-readable description of the error
  16. * @constructor
  17. */
  18. constructor(exitCode: number, code: string, message: string);
  19. }
  20. export class InvalidArgumentError extends CommanderError {
  21. /**
  22. * Constructs the InvalidArgumentError class
  23. * @param message - explanation of why argument is invalid
  24. * @constructor
  25. */
  26. constructor(message: string);
  27. }
  28. export { InvalidArgumentError as InvalidOptionArgumentError }; // deprecated old name
  29. export class Argument {
  30. description: string;
  31. required: boolean;
  32. variadic: boolean;
  33. /**
  34. * Initialize a new command argument with the given name and description.
  35. * The default is that the argument is required, and you can explicitly
  36. * indicate this with <> around the name. Put [] around the name for an optional argument.
  37. */
  38. constructor(arg: string, description?: string);
  39. /**
  40. * Return argument name.
  41. */
  42. name(): string;
  43. /**
  44. * Set the default value, and optionally supply the description to be displayed in the help.
  45. */
  46. default(value: unknown, description?: string): this;
  47. /**
  48. * Set the custom handler for processing CLI command arguments into argument values.
  49. */
  50. argParser<T>(fn: (value: string, previous: T) => T): this;
  51. /**
  52. * Only allow argument value to be one of choices.
  53. */
  54. choices(values: string[]): this;
  55. /**
  56. * Make option-argument required.
  57. */
  58. argRequired(): this;
  59. /**
  60. * Make option-argument optional.
  61. */
  62. argOptional(): this;
  63. }
  64. export class Option {
  65. flags: string;
  66. description: string;
  67. required: boolean; // A value must be supplied when the option is specified.
  68. optional: boolean; // A value is optional when the option is specified.
  69. variadic: boolean;
  70. mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line.
  71. optionFlags: string;
  72. short?: string;
  73. long?: string;
  74. negate: boolean;
  75. defaultValue?: any;
  76. defaultValueDescription?: string;
  77. parseArg?: <T>(value: string, previous: T) => T;
  78. hidden: boolean;
  79. argChoices?: string[];
  80. constructor(flags: string, description?: string);
  81. /**
  82. * Set the default value, and optionally supply the description to be displayed in the help.
  83. */
  84. default(value: unknown, description?: string): this;
  85. /**
  86. * Set environment variable to check for option value.
  87. * Priority order of option values is default < env < cli
  88. */
  89. env(name: string): this;
  90. /**
  91. * Calculate the full description, including defaultValue etc.
  92. */
  93. fullDescription(): string;
  94. /**
  95. * Set the custom handler for processing CLI option arguments into option values.
  96. */
  97. argParser<T>(fn: (value: string, previous: T) => T): this;
  98. /**
  99. * Whether the option is mandatory and must have a value after parsing.
  100. */
  101. makeOptionMandatory(mandatory?: boolean): this;
  102. /**
  103. * Hide option in help.
  104. */
  105. hideHelp(hide?: boolean): this;
  106. /**
  107. * Only allow option value to be one of choices.
  108. */
  109. choices(values: string[]): this;
  110. /**
  111. * Return option name.
  112. */
  113. name(): string;
  114. /**
  115. * Return option name, in a camelcase format that can be used
  116. * as a object attribute key.
  117. */
  118. attributeName(): string;
  119. }
  120. export class Help {
  121. /** output helpWidth, long lines are wrapped to fit */
  122. helpWidth?: number;
  123. sortSubcommands: boolean;
  124. sortOptions: boolean;
  125. constructor();
  126. /** Get the command term to show in the list of subcommands. */
  127. subcommandTerm(cmd: Command): string;
  128. /** Get the command description to show in the list of subcommands. */
  129. subcommandDescription(cmd: Command): string;
  130. /** Get the option term to show in the list of options. */
  131. optionTerm(option: Option): string;
  132. /** Get the option description to show in the list of options. */
  133. optionDescription(option: Option): string;
  134. /** Get the argument term to show in the list of arguments. */
  135. argumentTerm(argument: Argument): string;
  136. /** Get the argument description to show in the list of arguments. */
  137. argumentDescription(argument: Argument): string;
  138. /** Get the command usage to be displayed at the top of the built-in help. */
  139. commandUsage(cmd: Command): string;
  140. /** Get the description for the command. */
  141. commandDescription(cmd: Command): string;
  142. /** Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one. */
  143. visibleCommands(cmd: Command): Command[];
  144. /** Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one. */
  145. visibleOptions(cmd: Command): Option[];
  146. /** Get an array of the arguments which have descriptions. */
  147. visibleArguments(cmd: Command): Argument[];
  148. /** Get the longest command term length. */
  149. longestSubcommandTermLength(cmd: Command, helper: Help): number;
  150. /** Get the longest option term length. */
  151. longestOptionTermLength(cmd: Command, helper: Help): number;
  152. /** Get the longest argument term length. */
  153. longestArgumentTermLength(cmd: Command, helper: Help): number;
  154. /** Calculate the pad width from the maximum term length. */
  155. padWidth(cmd: Command, helper: Help): number;
  156. /**
  157. * Wrap the given string to width characters per line, with lines after the first indented.
  158. * Do not wrap if insufficient room for wrapping (minColumnWidth), or string is manually formatted.
  159. */
  160. wrap(str: string, width: number, indent: number, minColumnWidth?: number): string;
  161. /** Generate the built-in help text. */
  162. formatHelp(cmd: Command, helper: Help): string;
  163. }
  164. export type HelpConfiguration = Partial<Help>;
  165. export interface ParseOptions {
  166. from: 'node' | 'electron' | 'user';
  167. }
  168. export interface HelpContext { // optional parameter for .help() and .outputHelp()
  169. error: boolean;
  170. }
  171. export interface AddHelpTextContext { // passed to text function used with .addHelpText()
  172. error: boolean;
  173. command: Command;
  174. }
  175. export interface OutputConfiguration {
  176. writeOut?(str: string): void;
  177. writeErr?(str: string): void;
  178. getOutHelpWidth?(): number;
  179. getErrHelpWidth?(): number;
  180. outputError?(str: string, write: (str: string) => void): void;
  181. }
  182. export type AddHelpTextPosition = 'beforeAll' | 'before' | 'after' | 'afterAll';
  183. export type HookEvent = 'preAction' | 'postAction';
  184. export type OptionValueSource = 'default' | 'env' | 'config' | 'cli';
  185. export interface OptionValues {
  186. [key: string]: any;
  187. }
  188. export class Command {
  189. args: string[];
  190. processedArgs: any[];
  191. commands: Command[];
  192. parent: Command | null;
  193. constructor(name?: string);
  194. /**
  195. * Set the program version to `str`.
  196. *
  197. * This method auto-registers the "-V, --version" flag
  198. * which will print the version number when passed.
  199. *
  200. * You can optionally supply the flags and description to override the defaults.
  201. */
  202. version(str: string, flags?: string, description?: string): this;
  203. /**
  204. * Define a command, implemented using an action handler.
  205. *
  206. * @remarks
  207. * The command description is supplied using `.description`, not as a parameter to `.command`.
  208. *
  209. * @example
  210. * ```ts
  211. * program
  212. * .command('clone <source> [destination]')
  213. * .description('clone a repository into a newly created directory')
  214. * .action((source, destination) => {
  215. * console.log('clone command called');
  216. * });
  217. * ```
  218. *
  219. * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
  220. * @param opts - configuration options
  221. * @returns new command
  222. */
  223. command(nameAndArgs: string, opts?: CommandOptions): ReturnType<this['createCommand']>;
  224. /**
  225. * Define a command, implemented in a separate executable file.
  226. *
  227. * @remarks
  228. * The command description is supplied as the second parameter to `.command`.
  229. *
  230. * @example
  231. * ```ts
  232. * program
  233. * .command('start <service>', 'start named service')
  234. * .command('stop [service]', 'stop named service, or all if no name supplied');
  235. * ```
  236. *
  237. * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
  238. * @param description - description of executable command
  239. * @param opts - configuration options
  240. * @returns `this` command for chaining
  241. */
  242. command(nameAndArgs: string, description: string, opts?: ExecutableCommandOptions): this;
  243. /**
  244. * Factory routine to create a new unattached command.
  245. *
  246. * See .command() for creating an attached subcommand, which uses this routine to
  247. * create the command. You can override createCommand to customise subcommands.
  248. */
  249. createCommand(name?: string): Command;
  250. /**
  251. * Add a prepared subcommand.
  252. *
  253. * See .command() for creating an attached subcommand which inherits settings from its parent.
  254. *
  255. * @returns `this` command for chaining
  256. */
  257. addCommand(cmd: Command, opts?: CommandOptions): this;
  258. /**
  259. * Factory routine to create a new unattached argument.
  260. *
  261. * See .argument() for creating an attached argument, which uses this routine to
  262. * create the argument. You can override createArgument to return a custom argument.
  263. */
  264. createArgument(name: string, description?: string): Argument;
  265. /**
  266. * Define argument syntax for command.
  267. *
  268. * The default is that the argument is required, and you can explicitly
  269. * indicate this with <> around the name. Put [] around the name for an optional argument.
  270. *
  271. * @example
  272. * ```
  273. * program.argument('<input-file>');
  274. * program.argument('[output-file]');
  275. * ```
  276. *
  277. * @returns `this` command for chaining
  278. */
  279. argument<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
  280. argument(name: string, description?: string, defaultValue?: unknown): this;
  281. /**
  282. * Define argument syntax for command, adding a prepared argument.
  283. *
  284. * @returns `this` command for chaining
  285. */
  286. addArgument(arg: Argument): this;
  287. /**
  288. * Define argument syntax for command, adding multiple at once (without descriptions).
  289. *
  290. * See also .argument().
  291. *
  292. * @example
  293. * ```
  294. * program.arguments('<cmd> [env]');
  295. * ```
  296. *
  297. * @returns `this` command for chaining
  298. */
  299. arguments(names: string): this;
  300. /**
  301. * Override default decision whether to add implicit help command.
  302. *
  303. * @example
  304. * ```
  305. * addHelpCommand() // force on
  306. * addHelpCommand(false); // force off
  307. * addHelpCommand('help [cmd]', 'display help for [cmd]'); // force on with custom details
  308. * ```
  309. *
  310. * @returns `this` command for chaining
  311. */
  312. addHelpCommand(enableOrNameAndArgs?: string | boolean, description?: string): this;
  313. /**
  314. * Add hook for life cycle event.
  315. */
  316. hook(event: HookEvent, listener: (thisCommand: Command, actionCommand: Command) => void | Promise<void>): this;
  317. /**
  318. * Register callback to use as replacement for calling process.exit.
  319. */
  320. exitOverride(callback?: (err: CommanderError) => never|void): this;
  321. /**
  322. * You can customise the help with a subclass of Help by overriding createHelp,
  323. * or by overriding Help properties using configureHelp().
  324. */
  325. createHelp(): Help;
  326. /**
  327. * You can customise the help by overriding Help properties using configureHelp(),
  328. * or with a subclass of Help by overriding createHelp().
  329. */
  330. configureHelp(configuration: HelpConfiguration): this;
  331. /** Get configuration */
  332. configureHelp(): HelpConfiguration;
  333. /**
  334. * The default output goes to stdout and stderr. You can customise this for special
  335. * applications. You can also customise the display of errors by overriding outputError.
  336. *
  337. * The configuration properties are all functions:
  338. * ```
  339. * // functions to change where being written, stdout and stderr
  340. * writeOut(str)
  341. * writeErr(str)
  342. * // matching functions to specify width for wrapping help
  343. * getOutHelpWidth()
  344. * getErrHelpWidth()
  345. * // functions based on what is being written out
  346. * outputError(str, write) // used for displaying errors, and not used for displaying help
  347. * ```
  348. */
  349. configureOutput(configuration: OutputConfiguration): this;
  350. /** Get configuration */
  351. configureOutput(): OutputConfiguration;
  352. /**
  353. * Copy settings that are useful to have in common across root command and subcommands.
  354. *
  355. * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
  356. */
  357. copyInheritedSettings(sourceCommand: Command): this;
  358. /**
  359. * Display the help or a custom message after an error occurs.
  360. */
  361. showHelpAfterError(displayHelp?: boolean | string): this;
  362. /**
  363. * Display suggestion of similar commands for unknown commands, or options for unknown options.
  364. */
  365. showSuggestionAfterError(displaySuggestion?: boolean): this;
  366. /**
  367. * Register callback `fn` for the command.
  368. *
  369. * @example
  370. * ```
  371. * program
  372. * .command('serve')
  373. * .description('start service')
  374. * .action(function() {
  375. * // do work here
  376. * });
  377. * ```
  378. *
  379. * @returns `this` command for chaining
  380. */
  381. action(fn: (...args: any[]) => void | Promise<void>): this;
  382. /**
  383. * Define option with `flags`, `description` and optional
  384. * coercion `fn`.
  385. *
  386. * The `flags` string contains the short and/or long flags,
  387. * separated by comma, a pipe or space. The following are all valid
  388. * all will output this way when `--help` is used.
  389. *
  390. * "-p, --pepper"
  391. * "-p|--pepper"
  392. * "-p --pepper"
  393. *
  394. * @example
  395. * ```
  396. * // simple boolean defaulting to false
  397. * program.option('-p, --pepper', 'add pepper');
  398. *
  399. * --pepper
  400. * program.pepper
  401. * // => Boolean
  402. *
  403. * // simple boolean defaulting to true
  404. * program.option('-C, --no-cheese', 'remove cheese');
  405. *
  406. * program.cheese
  407. * // => true
  408. *
  409. * --no-cheese
  410. * program.cheese
  411. * // => false
  412. *
  413. * // required argument
  414. * program.option('-C, --chdir <path>', 'change the working directory');
  415. *
  416. * --chdir /tmp
  417. * program.chdir
  418. * // => "/tmp"
  419. *
  420. * // optional argument
  421. * program.option('-c, --cheese [type]', 'add cheese [marble]');
  422. * ```
  423. *
  424. * @returns `this` command for chaining
  425. */
  426. option(flags: string, description?: string, defaultValue?: string | boolean): this;
  427. option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
  428. /** @deprecated since v7, instead use choices or a custom function */
  429. option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
  430. /**
  431. * Define a required option, which must have a value after parsing. This usually means
  432. * the option must be specified on the command line. (Otherwise the same as .option().)
  433. *
  434. * The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
  435. */
  436. requiredOption(flags: string, description?: string, defaultValue?: string | boolean): this;
  437. requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;
  438. /** @deprecated since v7, instead use choices or a custom function */
  439. requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;
  440. /**
  441. * Factory routine to create a new unattached option.
  442. *
  443. * See .option() for creating an attached option, which uses this routine to
  444. * create the option. You can override createOption to return a custom option.
  445. */
  446. createOption(flags: string, description?: string): Option;
  447. /**
  448. * Add a prepared Option.
  449. *
  450. * See .option() and .requiredOption() for creating and attaching an option in a single call.
  451. */
  452. addOption(option: Option): this;
  453. /**
  454. * Whether to store option values as properties on command object,
  455. * or store separately (specify false). In both cases the option values can be accessed using .opts().
  456. *
  457. * @returns `this` command for chaining
  458. */
  459. storeOptionsAsProperties<T extends OptionValues>(): this & T;
  460. storeOptionsAsProperties<T extends OptionValues>(storeAsProperties: true): this & T;
  461. storeOptionsAsProperties(storeAsProperties?: boolean): this;
  462. /**
  463. * Retrieve option value.
  464. */
  465. getOptionValue(key: string): any;
  466. /**
  467. * Store option value.
  468. */
  469. setOptionValue(key: string, value: unknown): this;
  470. /**
  471. * Store option value and where the value came from.
  472. */
  473. setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this;
  474. /**
  475. * Retrieve option value source.
  476. */
  477. getOptionValueSource(key: string): OptionValueSource;
  478. /**
  479. * Alter parsing of short flags with optional values.
  480. *
  481. * @example
  482. * ```
  483. * // for `.option('-f,--flag [value]'):
  484. * .combineFlagAndOptionalValue(true) // `-f80` is treated like `--flag=80`, this is the default behaviour
  485. * .combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
  486. * ```
  487. *
  488. * @returns `this` command for chaining
  489. */
  490. combineFlagAndOptionalValue(combine?: boolean): this;
  491. /**
  492. * Allow unknown options on the command line.
  493. *
  494. * @returns `this` command for chaining
  495. */
  496. allowUnknownOption(allowUnknown?: boolean): this;
  497. /**
  498. * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
  499. *
  500. * @returns `this` command for chaining
  501. */
  502. allowExcessArguments(allowExcess?: boolean): this;
  503. /**
  504. * Enable positional options. Positional means global options are specified before subcommands which lets
  505. * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
  506. *
  507. * The default behaviour is non-positional and global options may appear anywhere on the command line.
  508. *
  509. * @returns `this` command for chaining
  510. */
  511. enablePositionalOptions(positional?: boolean): this;
  512. /**
  513. * Pass through options that come after command-arguments rather than treat them as command-options,
  514. * so actual command-options come before command-arguments. Turning this on for a subcommand requires
  515. * positional options to have been enabled on the program (parent commands).
  516. *
  517. * The default behaviour is non-positional and options may appear before or after command-arguments.
  518. *
  519. * @returns `this` command for chaining
  520. */
  521. passThroughOptions(passThrough?: boolean): this;
  522. /**
  523. * Parse `argv`, setting options and invoking commands when defined.
  524. *
  525. * The default expectation is that the arguments are from node and have the application as argv[0]
  526. * and the script being run in argv[1], with user parameters after that.
  527. *
  528. * @example
  529. * ```
  530. * program.parse(process.argv);
  531. * program.parse(); // implicitly use process.argv and auto-detect node vs electron conventions
  532. * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
  533. * ```
  534. *
  535. * @returns `this` command for chaining
  536. */
  537. parse(argv?: string[], options?: ParseOptions): this;
  538. /**
  539. * Parse `argv`, setting options and invoking commands when defined.
  540. *
  541. * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise.
  542. *
  543. * The default expectation is that the arguments are from node and have the application as argv[0]
  544. * and the script being run in argv[1], with user parameters after that.
  545. *
  546. * @example
  547. * ```
  548. * program.parseAsync(process.argv);
  549. * program.parseAsync(); // implicitly use process.argv and auto-detect node vs electron conventions
  550. * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
  551. * ```
  552. *
  553. * @returns Promise
  554. */
  555. parseAsync(argv?: string[], options?: ParseOptions): Promise<this>;
  556. /**
  557. * Parse options from `argv` removing known options,
  558. * and return argv split into operands and unknown arguments.
  559. *
  560. * argv => operands, unknown
  561. * --known kkk op => [op], []
  562. * op --known kkk => [op], []
  563. * sub --unknown uuu op => [sub], [--unknown uuu op]
  564. * sub -- --unknown uuu op => [sub --unknown uuu op], []
  565. */
  566. parseOptions(argv: string[]): ParseOptionsResult;
  567. /**
  568. * Return an object containing options as key-value pairs
  569. */
  570. opts<T extends OptionValues>(): T;
  571. /**
  572. * Set the description.
  573. *
  574. * @returns `this` command for chaining
  575. */
  576. description(str: string): this;
  577. /** @deprecated since v8, instead use .argument to add command argument with description */
  578. description(str: string, argsDescription: {[argName: string]: string}): this;
  579. /**
  580. * Get the description.
  581. */
  582. description(): string;
  583. /**
  584. * Set an alias for the command.
  585. *
  586. * You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
  587. *
  588. * @returns `this` command for chaining
  589. */
  590. alias(alias: string): this;
  591. /**
  592. * Get alias for the command.
  593. */
  594. alias(): string;
  595. /**
  596. * Set aliases for the command.
  597. *
  598. * Only the first alias is shown in the auto-generated help.
  599. *
  600. * @returns `this` command for chaining
  601. */
  602. aliases(aliases: string[]): this;
  603. /**
  604. * Get aliases for the command.
  605. */
  606. aliases(): string[];
  607. /**
  608. * Set the command usage.
  609. *
  610. * @returns `this` command for chaining
  611. */
  612. usage(str: string): this;
  613. /**
  614. * Get the command usage.
  615. */
  616. usage(): string;
  617. /**
  618. * Set the name of the command.
  619. *
  620. * @returns `this` command for chaining
  621. */
  622. name(str: string): this;
  623. /**
  624. * Get the name of the command.
  625. */
  626. name(): string;
  627. /**
  628. * Output help information for this command.
  629. *
  630. * Outputs built-in help, and custom text added using `.addHelpText()`.
  631. *
  632. */
  633. outputHelp(context?: HelpContext): void;
  634. /** @deprecated since v7 */
  635. outputHelp(cb?: (str: string) => string): void;
  636. /**
  637. * Return command help documentation.
  638. */
  639. helpInformation(context?: HelpContext): string;
  640. /**
  641. * You can pass in flags and a description to override the help
  642. * flags and help description for your command. Pass in false
  643. * to disable the built-in help option.
  644. */
  645. helpOption(flags?: string | boolean, description?: string): this;
  646. /**
  647. * Output help information and exit.
  648. *
  649. * Outputs built-in help, and custom text added using `.addHelpText()`.
  650. */
  651. help(context?: HelpContext): never;
  652. /** @deprecated since v7 */
  653. help(cb?: (str: string) => string): never;
  654. /**
  655. * Add additional text to be displayed with the built-in help.
  656. *
  657. * Position is 'before' or 'after' to affect just this command,
  658. * and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
  659. */
  660. addHelpText(position: AddHelpTextPosition, text: string): this;
  661. addHelpText(position: AddHelpTextPosition, text: (context: AddHelpTextContext) => string): this;
  662. /**
  663. * Add a listener (callback) for when events occur. (Implemented using EventEmitter.)
  664. */
  665. on(event: string | symbol, listener: (...args: any[]) => void): this;
  666. }
  667. export interface CommandOptions {
  668. hidden?: boolean;
  669. isDefault?: boolean;
  670. /** @deprecated since v7, replaced by hidden */
  671. noHelp?: boolean;
  672. }
  673. export interface ExecutableCommandOptions extends CommandOptions {
  674. executableFile?: string;
  675. }
  676. export interface ParseOptionsResult {
  677. operands: string[];
  678. unknown: string[];
  679. }
  680. export function createCommand(name?: string): Command;
  681. export function createOption(flags: string, description?: string): Option;
  682. export function createArgument(name: string, description?: string): Argument;
  683. export const program: Command;