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
|
---|
5 |
|
---|
6 | declare namespace local {
|
---|
7 |
|
---|
8 | class Option {
|
---|
9 | flags: string;
|
---|
10 | required: boolean;
|
---|
11 | optional: boolean;
|
---|
12 | bool: boolean;
|
---|
13 | short?: string;
|
---|
14 | long: string;
|
---|
15 | description: string;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Initialize a new `Option` with the given `flags` and `description`.
|
---|
19 | *
|
---|
20 | * @param {string} flags
|
---|
21 | * @param {string} [description]
|
---|
22 | */
|
---|
23 | constructor(flags: string, description?: string);
|
---|
24 | }
|
---|
25 |
|
---|
26 | class Command extends NodeJS.EventEmitter {
|
---|
27 | [key: string]: any;
|
---|
28 |
|
---|
29 | args: string[];
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Initialize a new `Command`.
|
---|
33 | *
|
---|
34 | * @param {string} [name]
|
---|
35 | */
|
---|
36 | constructor(name?: string);
|
---|
37 |
|
---|
38 | /**
|
---|
39 | * Set the program version to `str`.
|
---|
40 | *
|
---|
41 | * This method auto-registers the "-V, --version" flag
|
---|
42 | * which will print the version number when passed.
|
---|
43 | *
|
---|
44 | * @param {string} str
|
---|
45 | * @param {string} [flags]
|
---|
46 | * @returns {Command} for chaining
|
---|
47 | */
|
---|
48 | version(str: string, flags?: string): Command;
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Add command `name`.
|
---|
52 | *
|
---|
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.
|
---|
57 | *
|
---|
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.
|
---|
61 | *
|
---|
62 | * @example
|
---|
63 | * program
|
---|
64 | * .version('0.0.1')
|
---|
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')
|
---|
68 | *
|
---|
69 | * program
|
---|
70 | * .command('setup')
|
---|
71 | * .description('run remote setup commands')
|
---|
72 | * .action(function() {
|
---|
73 | * console.log('setup');
|
---|
74 | * });
|
---|
75 | *
|
---|
76 | * program
|
---|
77 | * .command('exec <cmd>')
|
---|
78 | * .description('run the given remote command')
|
---|
79 | * .action(function(cmd) {
|
---|
80 | * console.log('exec "%s"', cmd);
|
---|
81 | * });
|
---|
82 | *
|
---|
83 | * program
|
---|
84 | * .command('teardown <dir> [otherDirs...]')
|
---|
85 | * .description('run teardown commands')
|
---|
86 | * .action(function(dir, otherDirs) {
|
---|
87 | * console.log('dir "%s"', dir);
|
---|
88 | * if (otherDirs) {
|
---|
89 | * otherDirs.forEach(function (oDir) {
|
---|
90 | * console.log('dir "%s"', oDir);
|
---|
91 | * });
|
---|
92 | * }
|
---|
93 | * });
|
---|
94 | *
|
---|
95 | * program
|
---|
96 | * .command('*')
|
---|
97 | * .description('deploy the given env')
|
---|
98 | * .action(function(env) {
|
---|
99 | * console.log('deploying "%s"', env);
|
---|
100 | * });
|
---|
101 | *
|
---|
102 | * program.parse(process.argv);
|
---|
103 | *
|
---|
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
|
---|
108 | */
|
---|
109 | command(name: string, desc?: string, opts?: commander.CommandOptions): Command;
|
---|
110 |
|
---|
111 | /**
|
---|
112 | * Define argument syntax for the top-level command.
|
---|
113 | *
|
---|
114 | * @param {string} desc
|
---|
115 | * @returns {Command} for chaining
|
---|
116 | */
|
---|
117 | arguments(desc: string): Command;
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Parse expected `args`.
|
---|
121 | *
|
---|
122 | * For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
|
---|
123 | *
|
---|
124 | * @param {string[]} args
|
---|
125 | * @returns {Command} for chaining
|
---|
126 | */
|
---|
127 | parseExpectedArgs(args: string[]): Command;
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Register callback `fn` for the command.
|
---|
131 | *
|
---|
132 | * @example
|
---|
133 | * program
|
---|
134 | * .command('help')
|
---|
135 | * .description('display verbose help')
|
---|
136 | * .action(function() {
|
---|
137 | * // output help here
|
---|
138 | * });
|
---|
139 | *
|
---|
140 | * @param {(...args: any[]) => void} fn
|
---|
141 | * @returns {Command} for chaining
|
---|
142 | */
|
---|
143 | action(fn: (...args: any[]) => void): Command;
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Define option with `flags`, `description` and optional
|
---|
147 | * coercion `fn`.
|
---|
148 | *
|
---|
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.
|
---|
152 | *
|
---|
153 | * "-p, --pepper"
|
---|
154 | * "-p|--pepper"
|
---|
155 | * "-p --pepper"
|
---|
156 | *
|
---|
157 | * @example
|
---|
158 | * // simple boolean defaulting to false
|
---|
159 | * program.option('-p, --pepper', 'add pepper');
|
---|
160 | *
|
---|
161 | * --pepper
|
---|
162 | * program.pepper
|
---|
163 | * // => Boolean
|
---|
164 | *
|
---|
165 | * // simple boolean defaulting to true
|
---|
166 | * program.option('-C, --no-cheese', 'remove cheese');
|
---|
167 | *
|
---|
168 | * program.cheese
|
---|
169 | * // => true
|
---|
170 | *
|
---|
171 | * --no-cheese
|
---|
172 | * program.cheese
|
---|
173 | * // => false
|
---|
174 | *
|
---|
175 | * // required argument
|
---|
176 | * program.option('-C, --chdir <path>', 'change the working directory');
|
---|
177 | *
|
---|
178 | * --chdir /tmp
|
---|
179 | * program.chdir
|
---|
180 | * // => "/tmp"
|
---|
181 | *
|
---|
182 | * // optional argument
|
---|
183 | * program.option('-c, --cheese [type]', 'add cheese [marble]');
|
---|
184 | *
|
---|
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
|
---|
190 | */
|
---|
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;
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * Allow unknown options on the command line.
|
---|
196 | *
|
---|
197 | * @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options.
|
---|
198 | * @returns {Command} for chaining
|
---|
199 | */
|
---|
200 | allowUnknownOption(arg?: boolean): Command;
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Parse `argv`, settings options and invoking commands when defined.
|
---|
204 | *
|
---|
205 | * @param {string[]} argv
|
---|
206 | * @returns {Command} for chaining
|
---|
207 | */
|
---|
208 | parse(argv: string[]): Command;
|
---|
209 |
|
---|
210 | /**
|
---|
211 | * Parse options from `argv` returning `argv` void of these options.
|
---|
212 | *
|
---|
213 | * @param {string[]} argv
|
---|
214 | * @returns {ParseOptionsResult}
|
---|
215 | */
|
---|
216 | parseOptions(argv: string[]): commander.ParseOptionsResult;
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * Return an object containing options as key-value pairs
|
---|
220 | *
|
---|
221 | * @returns {{[key: string]: any}}
|
---|
222 | */
|
---|
223 | opts(): { [key: string]: any };
|
---|
224 |
|
---|
225 | /**
|
---|
226 | * Set the description to `str`.
|
---|
227 | *
|
---|
228 | * @param {string} str
|
---|
229 | * @param {{[argName: string]: string}} argsDescription
|
---|
230 | * @return {(Command | string)}
|
---|
231 | */
|
---|
232 | description(str: string, argsDescription?: {[argName: string]: string}): Command;
|
---|
233 | description(): string;
|
---|
234 |
|
---|
235 | /**
|
---|
236 | * Set an alias for the command.
|
---|
237 | *
|
---|
238 | * @param {string} alias
|
---|
239 | * @return {(Command | string)}
|
---|
240 | */
|
---|
241 | alias(alias: string): Command;
|
---|
242 | alias(): string;
|
---|
243 |
|
---|
244 | /**
|
---|
245 | * Set or get the command usage.
|
---|
246 | *
|
---|
247 | * @param {string} str
|
---|
248 | * @return {(Command | string)}
|
---|
249 | */
|
---|
250 | usage(str: string): Command;
|
---|
251 | usage(): string;
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * Set the name of the command.
|
---|
255 | *
|
---|
256 | * @param {string} str
|
---|
257 | * @return {Command}
|
---|
258 | */
|
---|
259 | name(str: string): Command;
|
---|
260 |
|
---|
261 | /**
|
---|
262 | * Get the name of the command.
|
---|
263 | *
|
---|
264 | * @return {string}
|
---|
265 | */
|
---|
266 | name(): string;
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * Output help information for this command.
|
---|
270 | *
|
---|
271 | * @param {(str: string) => string} [cb]
|
---|
272 | */
|
---|
273 | outputHelp(cb?: (str: string) => string): void;
|
---|
274 |
|
---|
275 | /** Output help information and exit.
|
---|
276 | *
|
---|
277 | * @param {(str: string) => string} [cb]
|
---|
278 | */
|
---|
279 | help(cb?: (str: string) => string): never;
|
---|
280 | }
|
---|
281 |
|
---|
282 | }
|
---|
283 |
|
---|
284 | declare namespace commander {
|
---|
285 |
|
---|
286 | type Command = local.Command
|
---|
287 |
|
---|
288 | type Option = local.Option
|
---|
289 |
|
---|
290 | interface CommandOptions {
|
---|
291 | noHelp?: boolean;
|
---|
292 | isDefault?: boolean;
|
---|
293 | }
|
---|
294 |
|
---|
295 | interface ParseOptionsResult {
|
---|
296 | args: string[];
|
---|
297 | unknown: string[];
|
---|
298 | }
|
---|
299 |
|
---|
300 | interface CommanderStatic extends Command {
|
---|
301 | Command: typeof local.Command;
|
---|
302 | Option: typeof local.Option;
|
---|
303 | CommandOptions: CommandOptions;
|
---|
304 | ParseOptionsResult: ParseOptionsResult;
|
---|
305 | }
|
---|
306 |
|
---|
307 | }
|
---|
308 |
|
---|
309 | declare const commander: commander.CommanderStatic;
|
---|
310 | export = commander;
|
---|