Skip to content
Myr

Use this instead of Command as a return type in TypeScript (#1180)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Dmitrii Maganov · committed by GitHub · parent a8a14c9 · Browse files · 2 files+24 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+24 added−24 removed

  • other:+24 added−24 removed

2 files+24 added−24 removed

modified:typings/index.d.ts+23 added-23 removed
38 unmodified lines
39 * which will print the version number when passed.40 * 41 * You can optionally supply the flags and description to override the defaults.42 */43 version(str: string, flags?: string, description?: string): Command;43 version(str: string, flags?: string, description?: string): this;4445 /**46 * Define a command, implemented using an action handler.47 *
32 unmodified lines
80 * @param description - description of executable command81 * @param opts - configuration options82 * @returns top level command for chaining more command definitions83 */84 command(nameAndArgs: string, description: string, opts?: commander.CommandOptions): Command;84 command(nameAndArgs: string, description: string, opts?: commander.CommandOptions): this;8586 /**87 * Add a prepared subcommand.88 * 89 * @returns parent command for chaining90 */91 addCommand(cmd: Command): Command;91 addCommand(cmd: Command): this;9293 /**94 * Define argument syntax for the top-level command.95 *96 * @returns Command for chaining97 */98 arguments(desc: string): Command;98 arguments(desc: string): this;99100 /**101 * Register callback to use as replacement for calling process.exit.102 */103 exitOverride(callback?: (err: CommanderError) => never|void): Command;103 exitOverride(callback?: (err: CommanderError) => never|void): this;104105 /**106 * Register callback `fn` for the command.107 *
6 unmodified lines
114 * });115 *116 * @returns Command for chaining117 */118 action(fn: (...args: any[]) => void | Promise<void>): Command;118 action(fn: (...args: any[]) => void | Promise<void>): this;119120 /**121 * Define option with `flags`, `description` and optional122 * coercion `fn`.
35 unmodified lines
158 * program.option('-c, --cheese [type]', 'add cheese [marble]');159 *160 * @returns Command for chaining161 */162 option(flags: string, description?: string, defaultValue?: string | boolean): Command;163 option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): Command;164 option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): Command;162 option(flags: string, description?: string, defaultValue?: string | boolean): this;163 option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;164 option<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;165166 /**167 * Define a required option, which must have a value after parsing. This usually means168 * the option must be specified on the command line. (Otherwise the same as .option().)169 *170 * The `flags` string should contain both the short and long flags, separated by comma, a pipe or space.171 */172 requiredOption(flags: string, description?: string, defaultValue?: string | boolean): Command;173 requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): Command;174 requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): Command;172 requiredOption(flags: string, description?: string, defaultValue?: string | boolean): this;173 requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean): this;174 requiredOption<T>(flags: string, description: string, fn: (value: string, previous: T) => T, defaultValue?: T): this;175176177 /**178 * Whether to store option values as properties on command object,179 * or store separately (specify false). In both cases the option values can be accessed using .opts().180 *181 * @return Command for chaining182 */183 storeOptionsAsProperties(value?: boolean): Command;183 storeOptionsAsProperties(value?: boolean): this;184185 /**186 * Whether to pass command to action handler,187 * or just the options (specify false).188 * 189 * @return Command for chaining190 */191 passCommandToAction(value?: boolean): Command;191 passCommandToAction(value?: boolean): this;192193 /**194 * Allow unknown options on the command line.195 *196 * @param [arg] if `true` or omitted, no error will be thrown for unknown options.197 * @returns Command for chaining198 */199 allowUnknownOption(arg?: boolean): Command;199 allowUnknownOption(arg?: boolean): this;200201 /**202 * Parse `argv`, setting options and invoking commands when defined.203 *
7 unmodified lines
211 * program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]212 * 213 * @returns Command for chaining214 */215 parse(argv?: string[], options?: ParseOptions): Command;215 parse(argv?: string[], options?: ParseOptions): this;216217 /**218 * Parse `argv`, setting options and invoking commands when defined.219 *
9 unmodified lines
229 * program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]230 *231 * @returns Promise232 */233 parseAsync(argv?: string[], options?: ParseOptions): Promise<any>;233 parseAsync(argv?: string[], options?: ParseOptions): Promise<this>;234235 /**236 * Parse options from `argv` removing known options,237 * and return argv split into operands and unknown arguments.
16 unmodified lines
254 * Set the description.255 * 256 * @returns Command for chaining257 */258 description(str: string, argsDescription?: {[argName: string]: string}): Command;258 description(str: string, argsDescription?: {[argName: string]: string}): this;259 /**260 * Get the description.261 */262 description(): string;
2 unmodified lines
265 * Set an alias for the command.266 * 267 * @returns Command for chaining268 */269 alias(alias: string): Command;269 alias(alias: string): this;270 /**271 * Get alias for the command.272 */273 alias(): string;
2 unmodified lines
276 * Set the command usage.277 * 278 * @returns Command for chaining279 */280 usage(str: string): Command;280 usage(str: string): this;281 /**282 * Get the command usage.283 */284 usage(): string;
2 unmodified lines
287 * Set the name of the command.288 * 289 * @returns Command for chaining290 */291 name(str: string): Command;291 name(str: string): this;292 /**293 * Get the name of the command.294 */295 name(): string;
14 unmodified lines
310 /**311 * You can pass in flags and a description to override the help312 * flags and help description for your command.313 */314 helpOption(flags?: string, description?: string): Command;314 helpOption(flags?: string, description?: string): this;315316 /** 317 * Output help information and exit.318 */
7 unmodified lines
326 * .on('--help', () -> {327 * console.log('See web site for more information.');328 * });329 */330 on(event: string | symbol, listener: (...args: any[]) => void): Command;330 on(event: string | symbol, listener: (...args: any[]) => void): this;331 }332 type CommandConstructor = { new (name?: string): Command };333334
21 unmodified lines
modified:index.js+1 added-1 removed
710 unmodified lines
711 */712713 parseAsync(argv, parseOptions) {714 this.parse(argv, parseOptions);715 return Promise.all(this._actionResults);715 return Promise.all(this._actionResults).then(() => this);716 };717718 /**719 * Execute a sub-command executable.
960 unmodified lines