1 // Type definitions for commander 2.11
2 // Project: https://github.com/visionmedia/commander.js
3 // 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>
4 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6 declare namespace local {
18 * Initialize a new `Option` with the given `flags` and `description`.
20 * @param {string} flags
21 * @param {string} [description]
23 constructor(flags: string, description?: string);
26 class Command extends NodeJS.EventEmitter {
32 * Initialize a new `Command`.
34 * @param {string} [name]
36 constructor(name?: string);
39 * Set the program version to `str`.
41 * This method auto-registers the "-V, --version" flag
42 * which will print the version number when passed.
45 * @param {string} [flags]
46 * @returns {Command} for chaining
48 version(str: string, flags?: string): Command;
53 * The `.action()` callback is invoked when the
54 * command `name` is specified via __ARGV__,
55 * and the remaining arguments are applied to the
56 * function for access.
58 * When the `name` is "*" an un-matched command
59 * will be passed as the first arg, followed by
60 * the rest of __ARGV__ remaining.
65 * .option('-C, --chdir <path>', 'change the working directory')
66 * .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
67 * .option('-T, --no-tests', 'ignore test hook')
71 * .description('run remote setup commands')
72 * .action(function() {
73 * console.log('setup');
77 * .command('exec <cmd>')
78 * .description('run the given remote command')
79 * .action(function(cmd) {
80 * console.log('exec "%s"', cmd);
84 * .command('teardown <dir> [otherDirs...]')
85 * .description('run teardown commands')
86 * .action(function(dir, otherDirs) {
87 * console.log('dir "%s"', dir);
89 * otherDirs.forEach(function (oDir) {
90 * console.log('dir "%s"', oDir);
97 * .description('deploy the given env')
98 * .action(function(env) {
99 * console.log('deploying "%s"', env);
102 * program.parse(process.argv);
104 * @param {string} name
105 * @param {string} [desc] for git-style sub-commands
106 * @param {CommandOptions} [opts] command options
107 * @returns {Command} the new command
109 command(name: string, desc?: string, opts?: commander.CommandOptions): Command;
112 * Define argument syntax for the top-level command.
114 * @param {string} desc
115 * @returns {Command} for chaining
117 arguments(desc: string): Command;
120 * Parse expected `args`.
122 * For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
124 * @param {string[]} args
125 * @returns {Command} for chaining
127 parseExpectedArgs(args: string[]): Command;
130 * Register callback `fn` for the command.
135 * .description('display verbose help')
136 * .action(function() {
137 * // output help here
140 * @param {(...args: any[]) => void} fn
141 * @returns {Command} for chaining
143 action(fn: (...args: any[]) => void): Command;
146 * Define option with `flags`, `description` and optional
149 * The `flags` string should contain both the short and long flags,
150 * separated by comma, a pipe or space. The following are all valid
151 * all will output this way when `--help` is used.
158 * // simple boolean defaulting to false
159 * program.option('-p, --pepper', 'add pepper');
165 * // simple boolean defaulting to true
166 * program.option('-C, --no-cheese', 'remove cheese');
175 * // required argument
176 * program.option('-C, --chdir <path>', 'change the working directory');
182 * // optional argument
183 * program.option('-c, --cheese [type]', 'add cheese [marble]');
185 * @param {string} flags
186 * @param {string} [description]
187 * @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default
188 * @param {*} [defaultValue]
189 * @returns {Command} for chaining
191 option(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command;
192 option(flags: string, description?: string, defaultValue?: any): Command;
195 * Allow unknown options on the command line.
197 * @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options.
198 * @returns {Command} for chaining
200 allowUnknownOption(arg?: boolean): Command;
203 * Parse `argv`, settings options and invoking commands when defined.
205 * @param {string[]} argv
206 * @returns {Command} for chaining
208 parse(argv: string[]): Command;
211 * Parse options from `argv` returning `argv` void of these options.
213 * @param {string[]} argv
214 * @returns {ParseOptionsResult}
216 parseOptions(argv: string[]): commander.ParseOptionsResult;
219 * Return an object containing options as key-value pairs
221 * @returns {{[key: string]: any}}
223 opts(): { [key: string]: any };
226 * Set the description to `str`.
228 * @param {string} str
229 * @param {{[argName: string]: string}} argsDescription
230 * @return {(Command | string)}
232 description(str: string, argsDescription?: {[argName: string]: string}): Command;
233 description(): string;
236 * Set an alias for the command.
238 * @param {string} alias
239 * @return {(Command | string)}
241 alias(alias: string): Command;
245 * Set or get the command usage.
247 * @param {string} str
248 * @return {(Command | string)}
250 usage(str: string): Command;
254 * Set the name of the command.
256 * @param {string} str
259 name(str: string): Command;
262 * Get the name of the command.
269 * Output help information for this command.
271 * @param {(str: string) => string} [cb]
273 outputHelp(cb?: (str: string) => string): void;
275 /** Output help information and exit.
277 * @param {(str: string) => string} [cb]
279 help(cb?: (str: string) => string): never;
284 declare namespace commander {
286 type Command = local.Command
288 type Option = local.Option
290 interface CommandOptions {
295 interface ParseOptionsResult {
300 interface CommanderStatic extends Command {
301 Command: typeof local.Command;
302 Option: typeof local.Option;
303 CommandOptions: CommandOptions;
304 ParseOptionsResult: ParseOptionsResult;
309 declare const commander: commander.CommanderStatic;