forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-getopt.d.ts
129 lines (106 loc) · 3.26 KB
/
node-getopt.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Type definitions for node-getopt 0.2.3
// Project: https://github.com/jiangmiao/node-getopt
// Definitions by: Karl.M.Cauchy <https://github.com/kcauchy>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/**
* Type Script Declaration for node-getopt
*/
declare module "node-getopt" {
interface StringMap {
[index: string]: string;
}
/**
* Parsed options.
*/
class ParsedOption {
public argv: string[];
public options: StringMap;
constructor(argv: string[], options: StringMap);
public empty() : boolean;
}
interface EventCallback {
(arguments: string[], options: StringMap) : void;
}
interface ErrorFunc {
(exception: Error): void;
}
interface OptionConfigurationArray {
[index: number]: string[];
}
class Getopt {
static HAS_ARGUMENT : boolean;
static NO_ARGUMENT : boolean;
static MULTI_SUPPORTED : boolean;
static SINGLE_ONLY : boolean;
static VERSION : string;
/**
* options is a set of option. each option contains 3 fields.
* [short_name, long_name_with_definition, comment]
* Definition:
* * '=ARG': has argument
* * '[=ARG]': has argument but optional
* * '+': multiple option supported
*
* ARG can be replaced by any word.
* @param options
*/
public constructor(options: any[]);
/**
* after parsing, trigger the action if optionName is found.
* the 'this' in action will be the instance of Getopt.
* @param name
* @param cb
*/
public on(name: string, cb: EventCallback) : Getopt;
public emit(name: string, cb: EventCallback) : Getopt;
/**
* parse argv
*
* Returns: {argv: '...', options: {...}}
*
*/
public parse(argv: string[]): ParsedOption;
/**
* alias of parse(process.argv.slice(2))
*/
public parse_system(): ParsedOption;
public parseSystem():ParsedOption;
/**
* Set help template. the placeholders will be replaced by getopt.
*
* Placeholders:
* * [[OPTIONS]] - The options list
*
* Returns: String
* @param help
*/
public setHelp(help: string): Getopt;
/**
* console.info(getopt.getHelp());
*/
public showHelp():Getopt;
/**
* Get the help generated.
*/
public getHelp(): string;
/**
* set help template to HELP if HELP is not empty.
* bind 'help' option to default action, show help and exit with 0.
* @param help
*/
public bindHelp(help?:string): Getopt;
public getVersion(): string;
static getVersion():string;
/**
* when parse failed callback will be trigger. default is display error message and exit with 1.
* @param errorFunc
*/
public error(errorFunc: ErrorFunc) : Getopt;
/**
* equals new Getopt(options)
* @param options
*/
static create(options: string[]): Getopt;
}
export = Getopt;
}