UNPKG

3.32 kBTypeScriptView Raw
1// Type definitions for command-line-args 5.0
2// Project: https://github.com/75lb/command-line-args
3// Definitions by: Lloyd Brookes <https://github.com/75lb>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5// TypeScript Version: 2.2
6
7/**
8 * Returns an object containing option values parsed from the command line. By default it parses the global `process.argv` array.
9 * Parsing is strict by default. To be more permissive, enable `partial` or `stopAtFirstUnknown` modes.
10 */
11declare function commandLineArgs(optionDefinitions: commandLineArgs.OptionDefinition[], options?: commandLineArgs.ParseOptions): commandLineArgs.CommandLineOptions;
12
13declare namespace commandLineArgs {
14 interface CommandLineOptions {
15 /**
16 * Command-line arguments not parsed by `commandLineArgs`.
17 */
18 _unknown?: string[];
19 [propName: string]: any;
20 }
21
22 interface ParseOptions {
23 /**
24 * An array of strings which if present will be parsed instead of `process.argv`.
25 */
26 argv?: string[];
27
28 /**
29 * If `true`, `commandLineArgs` will not throw on unknown options or values, instead returning them in the `_unknown` property of the output.
30 */
31 partial?: boolean;
32
33 /**
34 * If `true`, `commandLineArgs` will not throw on unknown options or values. Instead, parsing will stop at the first unknown argument
35 * and the remaining arguments returned in the `_unknown` property of the output. If set, `partial: true` is implied.
36 */
37 stopAtFirstUnknown?: boolean;
38
39 /**
40 * If `true`, options with hypenated names (e.g. `move-to`) will be returned in camel-case (e.g. `moveTo`).
41 */
42 camelCase?: boolean;
43 }
44
45 interface OptionDefinition {
46 /**
47 * The long option name.
48 */
49 name: string;
50
51 /**
52 * A setter function (you receive the output from this) enabling you to be specific about the type and value received. Typical values
53 * are `String` (the default), `Number` and `Boolean` but you can use a custom function. If no option value was set you will receive `null`.
54 */
55 type?: (input: string) => any;
56
57 /**
58 * A getopt-style short option name. Can be any single character except a digit or hyphen.
59 */
60 alias?: string;
61
62 /**
63 * Set this flag if the option accepts multiple values. In the output, you will receive an array of values each passed through the `type` function.
64 */
65 multiple?: boolean;
66
67 /**
68 * Identical to `multiple` but with greedy parsing disabled.
69 */
70 lazyMultiple?: boolean;
71
72 /**
73 * Any values unaccounted for by an option definition will be set on the `defaultOption`. This flag is typically set
74 * on the most commonly-used option to enable more concise usage.
75 */
76 defaultOption?: boolean;
77
78 /**
79 * An initial value for the option.
80 */
81 defaultValue?: any;
82
83 /**
84 * One or more group names the option belongs to.
85 */
86 group?: string | string[];
87 }
88}
89
90export = commandLineArgs;