1 | declare namespace optimist {
|
2 | interface Opt {
|
3 | alias?: string | string[] | undefined;
|
4 | default?: any;
|
5 | demand?: string | number | string[] | undefined;
|
6 | describe?: string | undefined;
|
7 | type?: string | undefined;
|
8 | }
|
9 |
|
10 | interface Parser {
|
11 | /** Implicitly use process.argv array to construct the argv object */
|
12 | argv: any;
|
13 | /** Pass in the process.argv yourself */
|
14 | (args: string[]): any;
|
15 | /** Use .parse() to do the same thing as treating optimist as a function */
|
16 | parse(args: string[]): any;
|
17 |
|
18 | // The types below follow the order and documentation of https://github.com/substack/node-optimist
|
19 |
|
20 | /** Set key names as equivalent such that updates to a key will propagate to aliases and vice-versa. */
|
21 | alias(key: string, alias: string | string[]): Parser;
|
22 | /** Take an object that maps keys to aliases. */
|
23 | alias(aliases: { [index: string]: string | string[] }): Parser;
|
24 |
|
25 | /** Set argv[key] to value if no option was specified on process.argv */
|
26 | default(key: string, value: any): Parser;
|
27 | /** Take an object that maps keys to default values */
|
28 | default(defaults: { [index: string]: any }): Parser;
|
29 |
|
30 | /** Show the usage information and exit if key wasn't specified in process.argv */
|
31 | demand(key: string): Parser;
|
32 | /** Demand at least as many non-option arguments, which show up in argv._ */
|
33 | demand(key: number): Parser;
|
34 | /** Demand each element in key */
|
35 | demand(key: string[]): Parser;
|
36 |
|
37 | /** Describe a key for the generated usage information */
|
38 | describe(key: string, desc: string): Parser;
|
39 | /** Take an object that maps keys to descriptions */
|
40 | describe(descriptions: { [index: string]: string }): Parser;
|
41 |
|
42 | /** Instead of chaining together, e.g. optimist.alias().demand().default()...,
|
43 | you can specify keys in opt for each of the chainable methods. */
|
44 | options(key: string, opt: Opt): Parser;
|
45 | /** Take an object that maps keys to opt parameters */
|
46 | options(options: { [index: string]: Opt }): Parser;
|
47 |
|
48 | /** Set a usage message to show which commands to use. Inside message,
|
49 | the string $0 will get interpolated to the current script name or node
|
50 | command for the present script similar to how $0 works in bash or perl. */
|
51 | usage(message: string): Parser;
|
52 |
|
53 | /** Check that certain conditions are met in the provided arguments. If fn
|
54 | throws or returns false, show the thrown error, usage information, and exit.
|
55 | */
|
56 | check(fn: (argv: any) => any): Parser;
|
57 |
|
58 | /** Interpret key as a boolean. If a non-flag option follows key in process.argv,
|
59 | that string won't get set as the value of key. If key never shows up as a
|
60 | flag in process.arguments, argv[key] will be false. */
|
61 | boolean(key: string): Parser;
|
62 | /** Interpret all the elements as booleans. */
|
63 | boolean(key: string[]): Parser;
|
64 |
|
65 | /** Tell the parser logic not to interpret key as a number or boolean. This can be useful if you need to preserve leading zeros in an input. */
|
66 | string(key: string): Parser;
|
67 | /** Interpret all the elements as strings */
|
68 | string(key: string[]): Parser;
|
69 |
|
70 | /** Format usage output to wrap at columns many columns. */
|
71 | wrap(columns: number): Parser;
|
72 |
|
73 | /** Return the generated usage string. */
|
74 | help(): string;
|
75 | /** Print the usage data using fn for printing (defaults to console.error). */
|
76 | showHelp(fn?: (message: string) => void): void;
|
77 | }
|
78 | }
|
79 |
|
80 | declare var optimist: optimist.Parser;
|
81 | export = optimist;
|