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