forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommander.d.ts
228 lines (198 loc) · 8.82 KB
/
commander.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Type definitions for commanderjs 1.1.1
// Project: https://github.com/visionmedia/commander.js
// Definitions by: Marcelo Dezem <http://github.com/mdezem>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module "commander" {
export interface Command {
/**
* The command name.
*/
name: string;
//
//
// NOTE: the methods below are COPIED to the module
// as functions exports. If changes need to be made here,
// remember to re-paste the definitions in the module.
// Read below to know why such ugly thing is required.
//
//
/**
* Register callback fn for the command.
*/
action(fn: (...args: any[]) => any): Command;
/**
* Define option with flags, description and optional coercion function and default value.
* The flags string should contain both the short and long flags
* separated by comma, a pipe or space. The following are all valid
* all will output this way when --help is used.
*
* "-p, --pepper"
* "-p|--pepper"
* "-p --pepper"
*
* @param flags the option flags.
* @param description the option description. The description is printed when "--help" is used.
* @param coerceFn (optional) specifies a callback function to coerce the option arg.
* @param defaultValue (optional) specifies a default value.
*/
option(flags: string, description: string, coerceFn?: (value: string) => any, defaultValue?: any): Command;
/**
* Sets the command version
*/
version(version: string): Command;
/**
* Parse the arguments array and invokes the commands passing the parsed options.
* @param argv the arguments array.
*/
parse(argv: string[]): Command;
/**
* Gets or sets the command description.
* @param description the new description for the command. When ommited this returns the current description, otherwise returns the current Command.
*/
description(description: string): Command;
description(): string;
/**
* Gets or sets the usage help string.
*/
usage(usage: string): Command;
usage(): string;
/*
* Prompt the user for a value, calling the callback function.
*
* Supports single-line and multi-line prompts.
* To issue a single-line prompt simply add a whitespace
* to the end of label, something like "name: ", whereas
* for a multi-line prompt omit this "description:".
* @param label the label string to be printed in console.
* @param callback a callback function to handle the inputed string.
*/
prompt(label: string, callback: (value: string) => any): void;
promptForNumber(label: string, callback: (value: number) => any): void;
promptForDate(label: string, callback: (value: Date) => any): void;
promptSingleLine(label: string, callback: (value: string) => any): void;
promptMultiLine(label: string, callback: (value: string) => any): void;
/**
* Prompt for password with a label, a optional mask char and callback function.
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
*/
password(label: string, mask: string, callback: (value: string) => any): void;
password(label: string, callback: (value: string) => any): void;
/**
* Prompts the user for a confirmation.
*/
confirm(label: string, callback: (flag: boolean) => any): void;
/**
* Prompt for password with str, mask char and callback fn(val).
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
*/
choose(options: string[], callback: (idx: number) => any): void;
choose(options: any[], callback: (idx: number) => any): void;
/**
* Add command with the specified name. Returns a new instance of Command.
*
* The .action() callback is invoked when the
* command name is specified via ARGV,
* and the remaining arguments are applied to the
* function for access.
* When the name is "*" an un-matched command
* will be passed as the first arg, followed by
* the rest of ARGV remaining.
*
* @param name the name of the command. Pass "*" to trap un-matched commands.
*/
command(name: string): Command;
}
//
//
// since TypeScript (and ECMA6) does not supports module.exports,
// there is no way to set the default Command instance as the module itself.
// It's ugly but the only way is to copy all the methods from Command
// and paste it in the module as functions exports.
//
//
/**
* Register callback fn for the command.
*/
export function action(fn: (...args: any[]) => any): Command;
/**
* Define option with flags, description and optional coercion function and default value.
* The flags string should contain both the short and long flags
* separated by comma, a pipe or space. The following are all valid
* all will output this way when --help is used.
*
* "-p, --pepper"
* "-p|--pepper"
* "-p --pepper"
*
* @param flags the option flags.
* @param description the option description. The description is printed when "--help" is used.
* @param coerceFn (optional) specifies a callback function to coerce the option arg.
* @param defaultValue (optional) specifies a default value.
*/
export function option(flags: string, description: string, coerceFn?: (value: string) => any, defaultValue?: any): Command;
/**
* Sets the command version
*/
export function version(version: string): Command;
/**
* Parse the arguments array and invokes the commands passing the parsed options.
* @param argv the arguments array.
*/
export function parse(argv: string[]): Command;
/**
* Gets or sets the command description.
* @param description the new description for the command. When ommited this returns the current description, otherwise returns the current Command.
*/
export function description(description: string): Command;
export function description(): string;
/**
* Gets or sets the usage help string.
*/
export function usage(usage: string): Command;
export function usage(): string;
/*
* Prompt the user for a value, calling the callback function.
*
* Supports single-line and multi-line prompts.
* To issue a single-line prompt simply add a whitespace
* to the end of label, something like "name: ", whereas
* for a multi-line prompt omit this "description:".
* @param label the label string to be printed in console.
* @param callback a callback function to handle the inputed string.
*/
export function prompt(label: string, callback: (value: string) => any): void;
export function promptForNumber(label: string, callback: (value: number) => any): void;
export function promptForDate(label: string, callback: (value: Date) => any): void;
export function promptSingleLine(label: string, callback: (value: string) => any): void;
export function promptMultiLine(label: string, callback: (value: string) => any): void;
/**
* Prompt for password with a label, a optional mask char and callback function.
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
*/
export function password(label: string, mask: string, callback: (value: string) => any): void;
export function password(label: string, callback: (value: string) => any): void;
/**
* Prompts the user for a confirmation.
*/
export function confirm(label: string, callback: (flag: boolean) => any): void;
/**
* Prompt for password with str, mask char and callback fn(val).
* The mask string defaults to '', aka no output is written while typing, you may want to use "*" etc.
*/
export function choose(options: string[], callback: (idx: number) => any): void;
export function choose(options: any[], callback: (idx: number) => any): void;
/**
* Add command with the specified name. Returns a new instance of Command.
*
* The .action() callback is invoked when the
* command name is specified via ARGV,
* and the remaining arguments are applied to the
* function for access.
* When the name is "*" an un-matched command
* will be passed as the first arg, followed by
* the rest of ARGV remaining.
*
* @param name the name of the command. Pass "*" to trap un-matched commands.
*/
export function command(name: string): Command;
}