diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-03-27 15:44:30 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-03-27 15:44:30 +0800 |
| commit | 1c0387549700d9ce64918fb5536e37350757c7dd (patch) | |
| tree | 8f27183c1f6f698afdc49017ed19821360280b51 /node_modules/commander/typings | |
| parent | bd543050c40bb988689fc20304bba0d8b4398a80 (diff) | |
updates
Diffstat (limited to 'node_modules/commander/typings')
| -rw-r--r-- | node_modules/commander/typings/index.d.ts | 293 |
1 files changed, 146 insertions, 147 deletions
diff --git a/node_modules/commander/typings/index.d.ts b/node_modules/commander/typings/index.d.ts index 082a3a3c..bcda2771 100644 --- a/node_modules/commander/typings/index.d.ts +++ b/node_modules/commander/typings/index.d.ts @@ -1,106 +1,130 @@ -// Type definitions for commander -// 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> +// Type definitions for commander 2.11 +// Project: https://github.com/visionmedia/commander.js +// 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> +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -///<reference types="node" /> +declare namespace local { -declare namespace commander { - - interface CommanderError extends Error { - code: string; - exitCode: number; - message: string; - nestedError?: string; - } - type CommanderErrorConstructor = { new (exitCode: number, code: string, message: string): CommanderError }; - - interface Option { + class Option { flags: string; - required: boolean; // A value must be supplied when the option is specified. - optional: boolean; // A value is optional when the option is specified. - mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line. + required: boolean; + optional: boolean; bool: boolean; short?: string; long: string; description: string; + + /** + * Initialize a new `Option` with the given `flags` and `description`. + * + * @param {string} flags + * @param {string} [description] + */ + constructor(flags: string, description?: string); } - type OptionConstructor = { new (flags: string, description?: string): Option }; - interface Command extends NodeJS.EventEmitter { - [key: string]: any; // options as properties + class Command extends NodeJS.EventEmitter { + [key: string]: any; args: string[]; /** - * Set the program version to `str`. + * Initialize a new `Command`. * - * This method auto-registers the "-V, --version" flag - * which will print the version number when passed. - * - * You can optionally supply the flags and description to override the defaults. + * @param {string} [name] */ - version(str: string, flags?: string, description?: string): Command; + constructor(name?: string); /** - * Define a command, implemented using an action handler. - * - * @remarks - * The command description is supplied using `.description`, not as a parameter to `.command`. - * - * @example - * ```ts - * program - * .command('clone <source> [destination]') - * .description('clone a repository into a newly created directory') - * .action((source, destination) => { - * console.log('clone command called'); - * }); - * ``` - * - * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...` - * @param opts - configuration options - * @returns new command + * Set the program version to `str`. + * + * This method auto-registers the "-V, --version" flag + * which will print the version number when passed. + * + * @param {string} str + * @param {string} [flags] + * @returns {Command} for chaining */ - command(nameAndArgs: string, opts?: CommandOptions): Command; + version(str: string, flags?: string): Command; + /** - * Define a command, implemented in a separate executable file. - * - * @remarks - * The command description is supplied as the second parameter to `.command`. - * + * Add command `name`. + * + * The `.action()` callback is invoked when the + * command `name` is specified via __ARGV__, + * and the remaining arguments are applied to the + * function for access. + * + * When the `name` is "*" an un-matched command + * will be passed as the first arg, followed by + * the rest of __ARGV__ remaining. + * * @example - * ```ts - * program - * .command('start <service>', 'start named service') - * .command('stop [service]', 'stop named serice, or all if no name supplied'); - * ``` - * - * @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...` - * @param description - description of executable command - * @param opts - configuration options - * @returns top level command for chaining more command definitions + * program + * .version('0.0.1') + * .option('-C, --chdir <path>', 'change the working directory') + * .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf') + * .option('-T, --no-tests', 'ignore test hook') + * + * program + * .command('setup') + * .description('run remote setup commands') + * .action(function() { + * console.log('setup'); + * }); + * + * program + * .command('exec <cmd>') + * .description('run the given remote command') + * .action(function(cmd) { + * console.log('exec "%s"', cmd); + * }); + * + * program + * .command('teardown <dir> [otherDirs...]') + * .description('run teardown commands') + * .action(function(dir, otherDirs) { + * console.log('dir "%s"', dir); + * if (otherDirs) { + * otherDirs.forEach(function (oDir) { + * console.log('dir "%s"', oDir); + * }); + * } + * }); + * + * program + * .command('*') + * .description('deploy the given env') + * .action(function(env) { + * console.log('deploying "%s"', env); + * }); + * + * program.parse(process.argv); + * + * @param {string} name + * @param {string} [desc] for git-style sub-commands + * @param {CommandOptions} [opts] command options + * @returns {Command} the new command */ - command(nameAndArgs: string, description: string, opts?: commander.CommandOptions): Command; + command(name: string, desc?: string, opts?: commander.CommandOptions): Command; /** * Define argument syntax for the top-level command. * - * @returns Command for chaining + * @param {string} desc + * @returns {Command} for chaining */ arguments(desc: string): Command; /** - * Parse expected `args`. + * Parse expected `args`. * * For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`. * - * @returns Command for chaining + * @param {string[]} args + * @returns {Command} for chaining */ - parseExpectedArgs(args: string[]): Command; - - /** - * Register callback to use as replacement for calling process.exit. - */ - exitOverride(callback?: (err: CommanderError) => never|void): Command; + parseExpectedArgs(args: string[]): Command; /** * Register callback `fn` for the command. @@ -113,9 +137,10 @@ declare namespace commander { * // output help here * }); * - * @returns Command for chaining + * @param {(...args: any[]) => void} fn + * @returns {Command} for chaining */ - action(fn: (...args: any[]) => void | Promise<void>): Command; + action(fn: (...args: any[]) => void): Command; /** * Define option with `flags`, `description` and optional @@ -157,141 +182,114 @@ declare namespace commander { * // optional argument * program.option('-c, --cheese [type]', 'add cheese [marble]'); * - * @returns Command for chaining + * @param {string} flags + * @param {string} [description] + * @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default + * @param {*} [defaultValue] + * @returns {Command} for chaining */ option(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command; option(flags: string, description?: string, defaultValue?: any): Command; /** - * Define a required option, which must have a value after parsing. This usually means - * the option must be specified on the command line. (Otherwise the same as .option().) - * - * The `flags` string should contain both the short and long flags, separated by comma, a pipe or space. - */ - requiredOption(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command; - requiredOption(flags: string, description?: string, defaultValue?: any): Command; - - - /** - * Whether to store option values as properties on command object, - * or store separately (specify false). In both cases the option values can be accessed using .opts(). - * - * @return Command for chaining - */ - storeOptionsAsProperties(value?: boolean): Command; - - /** - * Whether to pass command to action handler, - * or just the options (specify false). - * - * @return Command for chaining - */ - passCommandToAction(value?: boolean): Command; - - /** * Allow unknown options on the command line. * - * @param [arg] if `true` or omitted, no error will be thrown for unknown options. - * @returns Command for chaining + * @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options. + * @returns {Command} for chaining */ allowUnknownOption(arg?: boolean): Command; /** - * Parse `argv`, setting options and invoking commands when defined. + * Parse `argv`, settings options and invoking commands when defined. * - * @returns Command for chaining + * @param {string[]} argv + * @returns {Command} for chaining */ parse(argv: string[]): Command; /** - * Parse `argv`, setting options and invoking commands when defined. - * - * Use parseAsync instead of parse if any of your action handlers are async. Returns a Promise. - * - * @returns Promise - */ - parseAsync(argv: string[]): Promise<any>; - - /** * Parse options from `argv` returning `argv` void of these options. + * + * @param {string[]} argv + * @returns {ParseOptionsResult} */ parseOptions(argv: string[]): commander.ParseOptionsResult; /** * Return an object containing options as key-value pairs + * + * @returns {{[key: string]: any}} */ opts(): { [key: string]: any }; /** - * Set the description. - * - * @returns Command for chaining + * Set the description to `str`. + * + * @param {string} str + * @param {{[argName: string]: string}} argsDescription + * @return {(Command | string)} */ description(str: string, argsDescription?: {[argName: string]: string}): Command; - /** - * Get the description. - */ description(): string; /** * Set an alias for the command. - * - * @returns Command for chaining + * + * @param {string} alias + * @return {(Command | string)} */ alias(alias: string): Command; - /** - * Get alias for the command. - */ alias(): string; /** - * Set the command usage. - * - * @returns Command for chaining + * Set or get the command usage. + * + * @param {string} str + * @return {(Command | string)} */ usage(str: string): Command; - /** - * Get the command usage. - */ usage(): string; /** * Set the name of the command. - * - * @returns Command for chaining + * + * @param {string} str + * @return {Command} */ name(str: string): Command; + /** * Get the name of the command. + * + * @return {string} */ name(): string; /** * Output help information for this command. * - * When listener(s) are available for the helpLongFlag - * those callbacks are invoked. + * @param {(str: string) => string} [cb] */ outputHelp(cb?: (str: string) => string): void; - /** - * You can pass in flags and a description to override the help - * flags and help description for your command. - */ - helpOption(flags?: string, description?: string): Command; - - /** - * Output help information and exit. + /** Output help information and exit. + * + * @param {(str: string) => string} [cb] */ help(cb?: (str: string) => string): never; } - type CommandConstructor = { new (name?: string): Command }; +} + +declare namespace commander { + + type Command = local.Command + + type Option = local.Option interface CommandOptions { noHelp?: boolean; isDefault?: boolean; - executableFile?: string; } interface ParseOptionsResult { @@ -300,10 +298,11 @@ declare namespace commander { } interface CommanderStatic extends Command { - Command: CommandConstructor; - Option: OptionConstructor; - CommanderError:CommanderErrorConstructor; - } + Command: typeof local.Command; + Option: typeof local.Option; + CommandOptions: CommandOptions; + ParseOptionsResult: ParseOptionsResult; + } } |
