1 | declare namespace yargsParser {
|
2 | interface Arguments {
|
3 | /** Non-option arguments */
|
4 | _: Array<string | number>;
|
5 | /** Arguments after the end-of-options flag `--` */
|
6 | "--"?: Array<string | number>;
|
7 | /** All remaining options */
|
8 | [argName: string]: any;
|
9 | }
|
10 |
|
11 | interface DetailedArguments {
|
12 | /** An object representing the parsed value of `args` */
|
13 | argv: Arguments;
|
14 | /** Populated with an error object if an exception occurred during parsing. */
|
15 | error: Error | null;
|
16 | /** The inferred list of aliases built by combining lists in opts.alias. */
|
17 | aliases: { [alias: string]: string[] };
|
18 | /** Any new aliases added via camel-case expansion. */
|
19 | newAliases: { [alias: string]: boolean };
|
20 | /** The configuration loaded from the yargs stanza in package.json. */
|
21 | configuration: Configuration;
|
22 | }
|
23 |
|
24 | interface Configuration {
|
25 | /** Should variables prefixed with --no be treated as negations? Default is `true` */
|
26 | "boolean-negation": boolean;
|
27 | /** Should hyphenated arguments be expanded into camel-case aliases? Default is `true` */
|
28 | "camel-case-expansion": boolean;
|
29 | /** Should arrays be combined when provided by both command line arguments and a configuration file. Default is `false` */
|
30 | "combine-arrays": boolean;
|
31 | /** Should keys that contain . be treated as objects? Default is `true` */
|
32 | "dot-notation": boolean;
|
33 | /** Should arguments be coerced into an array when duplicated. Default is `true` */
|
34 | "duplicate-arguments-array": boolean;
|
35 | /** Should array arguments be coerced into a single array when duplicated. Default is `true` */
|
36 | "flatten-duplicate-arrays": boolean;
|
37 | /** Should arrays consume more than one positional argument following their flag. Default is `true` */
|
38 | "greedy-arrays": boolean;
|
39 | /** Should nargs consume dash options as well as positional arguments. Default is `false` */
|
40 | "nargs-eats-options": boolean;
|
41 | /** Should parsing stop at the first text argument? This is similar to how e.g. ssh parses its command line. Default is `false` */
|
42 | "halt-at-non-option": boolean;
|
43 | /** The prefix to use for negated boolean variables. Default is `'no-'` */
|
44 | "negation-prefix": string;
|
45 | /** Should keys that look like numbers be treated as such? Default is `true` */
|
46 | "parse-numbers": boolean;
|
47 | /** Should positional keys that look like numbers be treated as such? Default is `true` */
|
48 | "parse-positional-numbers": boolean;
|
49 | /** Should unparsed flags be stored in -- or _. Default is `false` */
|
50 | "populate--": boolean;
|
51 | /** Should a placeholder be added for keys not set via the corresponding CLI argument? Default is `false` */
|
52 | "set-placeholder-key": boolean;
|
53 | /** Should a group of short-options be treated as boolean flags? Default is `true` */
|
54 | "short-option-groups": boolean;
|
55 | /** Should aliases be removed before returning results? Default is `false` */
|
56 | "strip-aliased": boolean;
|
57 | /** Should dashed keys be removed before returning results? This option has no effect if camel-case-expansion is disabled. Default is `false` */
|
58 | "strip-dashed": boolean;
|
59 | /** Should unknown options be treated like regular arguments? An unknown option is one that is not configured in opts. Default is `false` */
|
60 | "unknown-options-as-args": boolean;
|
61 | }
|
62 |
|
63 | interface Options {
|
64 | /** An object representing the set of aliases for a key: `{ alias: { foo: ['f']} }`. */
|
65 | alias?: { [key: string]: string | string[] } | undefined;
|
66 | /**
|
67 | * Indicate that keys should be parsed as an array: `{ array: ['foo', 'bar'] }`.
|
68 | * Indicate that keys should be parsed as an array and coerced to booleans / numbers:
|
69 | * { array: [ { key: 'foo', boolean: true }, {key: 'bar', number: true} ] }`.
|
70 | */
|
71 | array?:
|
72 | | string[]
|
73 | | Array<{ key: string; boolean?: boolean | undefined; number?: boolean | undefined }>
|
74 | | undefined;
|
75 | /** Arguments should be parsed as booleans: `{ boolean: ['x', 'y'] }`. */
|
76 | boolean?: string[] | undefined;
|
77 | /** Indicate a key that represents a path to a configuration file (this file will be loaded and parsed). */
|
78 | config?: string | string[] | { [key: string]: boolean } | undefined;
|
79 | /** Provide configuration options to the yargs-parser. */
|
80 | configuration?: Partial<Configuration> | undefined;
|
81 | /**
|
82 | * Provide a custom synchronous function that returns a coerced value from the argument provided (or throws an error), e.g.
|
83 | * `{ coerce: { foo: function (arg) { return modifiedArg } } }`.
|
84 | */
|
85 | coerce?: { [key: string]: (arg: any) => any } | undefined;
|
86 | /** Indicate a key that should be used as a counter, e.g., `-vvv = {v: 3}`. */
|
87 | count?: string[] | undefined;
|
88 | /** Provide default values for keys: `{ default: { x: 33, y: 'hello world!' } }`. */
|
89 | default?: { [key: string]: any } | undefined;
|
90 | /** Environment variables (`process.env`) with the prefix provided should be parsed. */
|
91 | envPrefix?: string | undefined;
|
92 | /** Specify that a key requires n arguments: `{ narg: {x: 2} }`. */
|
93 | narg?: { [key: string]: number } | undefined;
|
94 | /** `path.normalize()` will be applied to values set to this key. */
|
95 | normalize?: string[] | undefined;
|
96 | /** Keys should be treated as strings (even if they resemble a number `-x 33`). */
|
97 | string?: string[] | undefined;
|
98 | /** Keys should be treated as numbers. */
|
99 | number?: string[] | undefined;
|
100 | }
|
101 |
|
102 | interface Parser {
|
103 | (argv: string | string[], opts?: Options): Arguments;
|
104 | detailed(argv: string | string[], opts?: Options): DetailedArguments;
|
105 | camelCase(str: string): string;
|
106 | decamelize(str: string, joinString?: string): string;
|
107 | looksLikeNumber(value: string | number | null | undefined): boolean;
|
108 | }
|
109 | }
|
110 |
|
111 | declare var yargsParser: yargsParser.Parser;
|
112 | export = yargsParser;
|