Websocket
[VSoRC/.git] / node_modules / wscat / node_modules / commander / typings / index.d.ts
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]: string}}
222      */
223     opts(): { [key: string]: string };
224
225     /**
226      * Set the description to `str`.
227      *
228      * @param {string} str
229      * @return {(Command | string)}
230      */
231     description(str: string): Command;
232     description(): string;
233
234     /**
235      * Set an alias for the command.
236      *
237      * @param {string} alias
238      * @return {(Command | string)}
239      */
240     alias(alias: string): Command;
241     alias(): string;
242
243     /**
244      * Set or get the command usage.
245      *
246      * @param {string} str
247      * @return {(Command | string)}
248      */
249     usage(str: string): Command;
250     usage(): string;
251
252     /**
253      * Set the name of the command.
254      *
255      * @param {string} str
256      * @return {Command}
257      */
258     name(str: string): Command;
259
260     /**
261      * Get the name of the command.
262      *
263      * @return {string}
264      */
265     name(): string;
266
267     /**
268      * Output help information for this command.
269      *
270      * @param {(str: string) => string} [cb]
271      */
272     outputHelp(cb?: (str: string) => string): void;
273
274     /** Output help information and exit.
275      *
276      * @param {(str: string) => string} [cb]
277      */
278     help(cb?: (str: string) => string): void;
279   }
280
281 }
282
283 declare namespace commander {
284
285     type Command = local.Command
286
287     type Option = local.Option
288
289     interface CommandOptions {
290         noHelp?: boolean;
291         isDefault?: boolean;
292     }
293
294     interface ParseOptionsResult {
295         args: string[];
296         unknown: string[];
297     }
298
299     interface CommanderStatic extends Command {
300         Command: typeof local.Command;
301         Option: typeof local.Option;
302         CommandOptions: CommandOptions;
303         ParseOptionsResult: ParseOptionsResult;
304     }
305
306 }
307
308 declare const commander: commander.CommanderStatic;
309 export = commander;