@bemoje/cli 2.1.5 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +577 -789
- package/index.mjs +558 -684
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { Simplify, SetFieldType, SetRequired, AllUnionFields, CamelCase } from '
|
|
|
2
2
|
|
|
3
3
|
/** Logger interface defining methods for different log levels. */
|
|
4
4
|
interface Logger {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
start: (...args: unknown[]) => void;
|
|
6
|
+
done: (...args: unknown[]) => void;
|
|
7
|
+
info: (...args: unknown[]) => void;
|
|
8
|
+
log: (...args: unknown[]) => void;
|
|
9
|
+
warn: (...args: unknown[]) => void;
|
|
10
|
+
error: (...args: unknown[]) => void;
|
|
11
|
+
debug: (...args: unknown[]) => void;
|
|
12
12
|
}
|
|
13
13
|
/** Parsed command-line arguments */
|
|
14
14
|
type Arguments = (undefined | string | string[])[];
|
|
@@ -16,318 +16,296 @@ type Arguments = (undefined | string | string[])[];
|
|
|
16
16
|
type Options = Record<string, undefined | boolean | string | string[]>;
|
|
17
17
|
/** Result of parsing command-line input, including arguments, options, triggered actions, and execution method */
|
|
18
18
|
type SubCommands = {
|
|
19
|
-
|
|
19
|
+
[name: string]: Command<Arguments, Options, any>;
|
|
20
20
|
};
|
|
21
21
|
/** Base descriptor for command-line arguments with shared properties */
|
|
22
22
|
interface Argument {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
usage: string;
|
|
24
|
+
name: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
variadic?: boolean;
|
|
28
|
+
choices?: string[];
|
|
29
|
+
defaultValue?: string | string[];
|
|
30
|
+
defaultValueDescription?: string;
|
|
31
31
|
}
|
|
32
32
|
/** Base descriptor for command-line options with shared properties */
|
|
33
33
|
interface Option {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
34
|
+
type: 'boolean' | 'string';
|
|
35
|
+
flags: string;
|
|
36
|
+
short: string;
|
|
37
|
+
long: string;
|
|
38
|
+
name: string;
|
|
39
|
+
argName?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
required?: boolean;
|
|
42
|
+
variadic?: boolean;
|
|
43
|
+
negate?: boolean;
|
|
44
|
+
defaultValue?: boolean | string | string[];
|
|
45
|
+
defaultValueDescription?: string;
|
|
46
|
+
env?: string;
|
|
47
|
+
hidden?: boolean;
|
|
48
|
+
choices?: string[];
|
|
49
|
+
group?: string;
|
|
50
50
|
}
|
|
51
51
|
/** Complete command configuration including all properties and substructures */
|
|
52
52
|
interface ICommand {
|
|
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
|
-
|
|
53
|
+
/** Parent command if this is a subcommand */
|
|
54
|
+
readonly parent?: ICommand;
|
|
55
|
+
/** Help configuration and rendering */
|
|
56
|
+
/** Command name used for invocation */
|
|
57
|
+
name: string;
|
|
58
|
+
/** Alternative names for this command */
|
|
59
|
+
aliases: string[];
|
|
60
|
+
/** Optional version string */
|
|
61
|
+
version?: string;
|
|
62
|
+
/** Full command description */
|
|
63
|
+
description: string;
|
|
64
|
+
/** Brief single-line description */
|
|
65
|
+
summary?: string;
|
|
66
|
+
/** Whether command should be hidden from help */
|
|
67
|
+
hidden?: boolean;
|
|
68
|
+
/** Group name for organizing commands in help */
|
|
69
|
+
group?: string;
|
|
70
|
+
/** Positional arguments */
|
|
71
|
+
arguments: Argument[];
|
|
72
|
+
/** Named options/flags */
|
|
73
|
+
options: Option[];
|
|
74
|
+
/** Child subcommands */
|
|
75
|
+
commands: {
|
|
76
|
+
[name: string]: ICommand;
|
|
77
|
+
};
|
|
78
78
|
}
|
|
79
79
|
interface IHelp {
|
|
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
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Generate the built-in help text.
|
|
247
|
-
*/
|
|
248
|
-
render(): string;
|
|
80
|
+
/** output helpWidth, long lines are wrapped to fit */
|
|
81
|
+
helpWidth: number;
|
|
82
|
+
minWidthToWrap: number;
|
|
83
|
+
sortSubcommands: boolean;
|
|
84
|
+
sortOptions: boolean;
|
|
85
|
+
usageDisplayOptionsAs: string;
|
|
86
|
+
usageDisplaySubcommandAs: string;
|
|
87
|
+
/**
|
|
88
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
89
|
+
*/
|
|
90
|
+
visibleCommands(): ICommand[];
|
|
91
|
+
/**
|
|
92
|
+
* Compare options for sort.
|
|
93
|
+
*/
|
|
94
|
+
compareOptions(a: Option, b: Option): number;
|
|
95
|
+
/**
|
|
96
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
97
|
+
*/
|
|
98
|
+
visibleOptions(): Option[];
|
|
99
|
+
/**
|
|
100
|
+
* Get an array of the arguments if any have a description.
|
|
101
|
+
*/
|
|
102
|
+
visibleArguments(): Argument[];
|
|
103
|
+
/**
|
|
104
|
+
* Get the command term to show in the list of subcommands.
|
|
105
|
+
*/
|
|
106
|
+
subcommandTerm(sub: ICommand): string;
|
|
107
|
+
/**
|
|
108
|
+
* Get the option term to show in the list of options.
|
|
109
|
+
*/
|
|
110
|
+
optionTerm(option: Option): string;
|
|
111
|
+
/**
|
|
112
|
+
* Get the argument term to show in the list of arguments.
|
|
113
|
+
*/
|
|
114
|
+
argumentTerm(argument: Argument): string;
|
|
115
|
+
/**
|
|
116
|
+
* Get the longest subcommand primary alias length.
|
|
117
|
+
*/
|
|
118
|
+
longestSubcommandAliasLength(): number;
|
|
119
|
+
/**
|
|
120
|
+
* Get the longest subcommand term length.
|
|
121
|
+
*/
|
|
122
|
+
longestSubcommandTermLength(): number;
|
|
123
|
+
/**
|
|
124
|
+
* Get the longest option term length.
|
|
125
|
+
*/
|
|
126
|
+
longestOptionTermLength(): number;
|
|
127
|
+
/**
|
|
128
|
+
* Get the longest argument term length.
|
|
129
|
+
*/
|
|
130
|
+
longestArgumentTermLength(): number;
|
|
131
|
+
/**
|
|
132
|
+
* Get the command usage to be displayed at the top of the built-in help.
|
|
133
|
+
*/
|
|
134
|
+
commandUsage(): string;
|
|
135
|
+
/**
|
|
136
|
+
* Get the description for the command.
|
|
137
|
+
*/
|
|
138
|
+
commandDescription(): string;
|
|
139
|
+
/**
|
|
140
|
+
* Get the subcommand summary to show in the list of subcommands.
|
|
141
|
+
* (Fallback to description for backwards compatibility.)
|
|
142
|
+
*/
|
|
143
|
+
subcommandDescription(sub: ICommand): string;
|
|
144
|
+
/**
|
|
145
|
+
* Get the option description to show in the list of options.
|
|
146
|
+
*/
|
|
147
|
+
optionDescription(option: Option): string;
|
|
148
|
+
/**
|
|
149
|
+
* Get the argument description to show in the list of arguments.
|
|
150
|
+
*/
|
|
151
|
+
argumentDescription(argument: Argument): string;
|
|
152
|
+
/**
|
|
153
|
+
* Format a list of items, given a heading and an array of formatted items.
|
|
154
|
+
*/
|
|
155
|
+
formatItemList(heading: string, items: string[]): string[];
|
|
156
|
+
/**
|
|
157
|
+
* Group items by their help group heading.
|
|
158
|
+
*/
|
|
159
|
+
groupItems<T extends ICommand | Option>(unsortedItems: T[], visibleItems: T[], getGroup: (item: T) => string): Map<string, T[]>;
|
|
160
|
+
/**
|
|
161
|
+
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
162
|
+
*/
|
|
163
|
+
displayWidth(str: string): number;
|
|
164
|
+
/**
|
|
165
|
+
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
166
|
+
*/
|
|
167
|
+
styleTitle(str: string): string;
|
|
168
|
+
/**
|
|
169
|
+
* Style the usage line for displaying in the help. Applies specific styling to different parts like options, commands, and arguments.
|
|
170
|
+
*/
|
|
171
|
+
styleUsage(str: string): string;
|
|
172
|
+
/**
|
|
173
|
+
* Style command descriptions for display in help output.
|
|
174
|
+
*/
|
|
175
|
+
styleCommandDescription(str: string): string;
|
|
176
|
+
/**
|
|
177
|
+
* Style option descriptions for display in help output.
|
|
178
|
+
*/
|
|
179
|
+
styleOptionDescription(str: string): string;
|
|
180
|
+
/**
|
|
181
|
+
* Style subcommand descriptions for display in help output.
|
|
182
|
+
*/
|
|
183
|
+
styleSubcommandDescription(str: string): string;
|
|
184
|
+
/**
|
|
185
|
+
* Style argument descriptions for display in help output.
|
|
186
|
+
*/
|
|
187
|
+
styleArgumentDescription(str: string): string;
|
|
188
|
+
/**
|
|
189
|
+
* Base style used by descriptions. Override in subclass to apply custom formatting.
|
|
190
|
+
*/
|
|
191
|
+
styleDescriptionText(str: string): string;
|
|
192
|
+
/**
|
|
193
|
+
* Style option terms (flags) for display in help output.
|
|
194
|
+
*/
|
|
195
|
+
styleOptionTerm(str: string): string;
|
|
196
|
+
/**
|
|
197
|
+
* Style subcommand terms for display in help output. Applies specific styling to different parts like options and arguments.
|
|
198
|
+
*/
|
|
199
|
+
styleSubcommandTerm(str: string): string;
|
|
200
|
+
/**
|
|
201
|
+
* Style argument terms for display in help output.
|
|
202
|
+
*/
|
|
203
|
+
styleArgumentTerm(str: string): string;
|
|
204
|
+
/**
|
|
205
|
+
* Base style used in terms and usage for options. Override in subclass to apply custom formatting.
|
|
206
|
+
*/
|
|
207
|
+
styleOptionText(str: string): string;
|
|
208
|
+
/**
|
|
209
|
+
* Base style used in terms and usage for arguments. Override in subclass to apply custom formatting.
|
|
210
|
+
*/
|
|
211
|
+
styleArgumentText(str: string): string;
|
|
212
|
+
/**
|
|
213
|
+
* Base style used in terms and usage for subcommands. Override in subclass to apply custom formatting.
|
|
214
|
+
*/
|
|
215
|
+
styleSubcommandText(str: string): string;
|
|
216
|
+
/**
|
|
217
|
+
* Base style used in terms and usage for commands. Override in subclass to apply custom formatting.
|
|
218
|
+
*/
|
|
219
|
+
styleCommandText(str: string): string;
|
|
220
|
+
/**
|
|
221
|
+
* Calculate the pad width from the maximum term length.
|
|
222
|
+
*/
|
|
223
|
+
padWidth(): number;
|
|
224
|
+
/**
|
|
225
|
+
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
226
|
+
*/
|
|
227
|
+
preformatted(str: string): boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
230
|
+
*
|
|
231
|
+
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
232
|
+
* TTT DDD DDDD
|
|
233
|
+
* DD DDD
|
|
234
|
+
*/
|
|
235
|
+
formatItem(term: string, termWidth: number, description: string): string;
|
|
236
|
+
/**
|
|
237
|
+
* Wrap a string at whitespace, preserving existing line breaks.
|
|
238
|
+
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
239
|
+
*/
|
|
240
|
+
boxWrap(str: string, width: number): string;
|
|
241
|
+
/**
|
|
242
|
+
* Generate the built-in help text.
|
|
243
|
+
*/
|
|
244
|
+
render(): string;
|
|
249
245
|
}
|
|
250
246
|
/** Action handler function type, which receives parsed arguments and options as well as metadata about the command execution context. */
|
|
251
|
-
type ActionHandler<A extends Arguments, O extends Options, Subs extends SubCommands> = (
|
|
252
|
-
...args: [
|
|
247
|
+
type ActionHandler<A extends Arguments, O extends Options, Subs extends SubCommands> = (...args: [
|
|
253
248
|
...A,
|
|
254
249
|
O,
|
|
255
250
|
{
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
) => Promise<void> | void;
|
|
251
|
+
path: string[];
|
|
252
|
+
name: string;
|
|
253
|
+
argv: string[];
|
|
254
|
+
args: A;
|
|
255
|
+
opts: O;
|
|
256
|
+
errors?: string[];
|
|
257
|
+
cmd: Command<A, O, Subs>;
|
|
258
|
+
logger: Logger;
|
|
259
|
+
}
|
|
260
|
+
]) => Promise<void> | void;
|
|
267
261
|
/** Predicate function type for hooks, which receives the same metadata as action handlers and returns a boolean indicating whether the hook's action should be executed. */
|
|
268
|
-
type HookPredicate<
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
args: A;
|
|
277
|
-
opts: O;
|
|
278
|
-
errors?: string[];
|
|
279
|
-
cmd: Command<A, O, Subs>;
|
|
262
|
+
type HookPredicate<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = (data: {
|
|
263
|
+
path: string[];
|
|
264
|
+
name: string;
|
|
265
|
+
argv: string[];
|
|
266
|
+
args: A;
|
|
267
|
+
opts: O;
|
|
268
|
+
errors?: string[];
|
|
269
|
+
cmd: Command<A, O, Subs>;
|
|
280
270
|
}) => boolean;
|
|
281
271
|
/** Action handler function type for hooks, which receives the same metadata as action handlers and is executed when its predicate returns true. Can also throw to indicate an error. */
|
|
282
|
-
type HookActionHandler<
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
args: A;
|
|
291
|
-
opts: O;
|
|
292
|
-
errors?: string[];
|
|
293
|
-
cmd: Command<A, O, Subs>;
|
|
272
|
+
type HookActionHandler<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = (data: {
|
|
273
|
+
path: string[];
|
|
274
|
+
name: string;
|
|
275
|
+
argv: string[];
|
|
276
|
+
args: A;
|
|
277
|
+
opts: O;
|
|
278
|
+
errors?: string[];
|
|
279
|
+
cmd: Command<A, O, Subs>;
|
|
294
280
|
}) => Promise<void> | void | never;
|
|
295
281
|
/** Hook definition type, which includes the option name that triggers the hook, a predicate function to determine when the hook should run, and an action handler to execute when triggered. */
|
|
296
|
-
type HookDefinition<
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
> = {
|
|
301
|
-
name: keyof O;
|
|
302
|
-
predicate: HookPredicate<A, O, Subs>;
|
|
303
|
-
action: HookActionHandler<A, O, Subs>;
|
|
282
|
+
type HookDefinition<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = {
|
|
283
|
+
name: keyof O;
|
|
284
|
+
predicate: HookPredicate<A, O, Subs>;
|
|
285
|
+
action: HookActionHandler<A, O, Subs>;
|
|
304
286
|
};
|
|
305
287
|
/**
|
|
306
288
|
* @see Command.prototype.parseArgv
|
|
307
289
|
*/
|
|
308
|
-
type ParseArgvResult<
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
/** Names of all triggered hooks whose predicate returned true */
|
|
328
|
-
hooks: HookDefinition<A, O, Subs>[];
|
|
329
|
-
/** Calls the action handler with its expected args */
|
|
330
|
-
execute: () => Promise<void>;
|
|
290
|
+
type ParseArgvResult<A extends Arguments = Arguments, O extends Options = Options, Subs extends SubCommands = SubCommands> = {
|
|
291
|
+
/** The command or subcommand instance */
|
|
292
|
+
get cmd(): Command<A, O, Subs>;
|
|
293
|
+
/** The part of argv that makes out a subcommand path, or empty array when root command */
|
|
294
|
+
path: string[];
|
|
295
|
+
/** Command namer */
|
|
296
|
+
name: string;
|
|
297
|
+
/** Original argv array passed in or from process.argv, excluding subcommand path */
|
|
298
|
+
argv: string[];
|
|
299
|
+
/** Parsed arguments */
|
|
300
|
+
args: A;
|
|
301
|
+
/** Parsed options */
|
|
302
|
+
opts: O;
|
|
303
|
+
/** Error messages if parsing failed, otherwise undefined */
|
|
304
|
+
errors?: string[];
|
|
305
|
+
/** Names of all triggered hooks whose predicate returned true */
|
|
306
|
+
hooks: HookDefinition<A, O, Subs>[];
|
|
307
|
+
/** Calls the action handler with its expected args */
|
|
308
|
+
execute: () => Promise<void>;
|
|
331
309
|
};
|
|
332
310
|
/** required variadic argument */
|
|
333
311
|
type RequiredVariadicArgumentUsage = `<${string}...>`;
|
|
@@ -338,116 +316,70 @@ type RequiredArgumentUsage = `<${string}>`;
|
|
|
338
316
|
/** optional argument */
|
|
339
317
|
type OptionalArgumentUsage = `[${string}]`;
|
|
340
318
|
/** Union of all argument usage pattern types */
|
|
341
|
-
type ArgumentUsage =
|
|
342
|
-
| RequiredVariadicArgumentUsage
|
|
343
|
-
| OptionalVariadicArgumentUsage
|
|
344
|
-
| RequiredArgumentUsage
|
|
345
|
-
| OptionalArgumentUsage;
|
|
319
|
+
type ArgumentUsage = RequiredVariadicArgumentUsage | OptionalVariadicArgumentUsage | RequiredArgumentUsage | OptionalArgumentUsage;
|
|
346
320
|
/** Helper type to infer allowed argument usage patterns based on the command's existing argument types */
|
|
347
|
-
type InferArgumentUsage<T extends Command<any, any, any>> =
|
|
348
|
-
T extends Command<infer A, any>
|
|
349
|
-
? A extends string[]
|
|
350
|
-
? ArgumentUsage
|
|
351
|
-
: A extends (string | (string | undefined))[]
|
|
352
|
-
? OptionalArgumentUsage | OptionalVariadicArgumentUsage
|
|
353
|
-
: never
|
|
354
|
-
: never;
|
|
321
|
+
type InferArgumentUsage<T extends Command<any, any, any>> = T extends Command<infer A, any> ? A extends string[] ? ArgumentUsage : A extends (string | (string | undefined))[] ? OptionalArgumentUsage | OptionalVariadicArgumentUsage : never : never;
|
|
355
322
|
/** Helper type to infer allowed argument usage patterns based on the command's existing argument types */
|
|
356
|
-
type AllowedArgumentUsage<T extends Command<any, any, any>, Usage extends ArgumentUsage> =
|
|
357
|
-
Usage extends InferArgumentUsage<T> ? Usage : never;
|
|
323
|
+
type AllowedArgumentUsage<T extends Command<any, any, any>, Usage extends ArgumentUsage> = Usage extends InferArgumentUsage<T> ? Usage : never;
|
|
358
324
|
/** Base type for addArgument options, extended by specific required/optional and variadic/non-variadic argument option types */
|
|
359
|
-
type ArgumentOptionsBase = Omit<
|
|
360
|
-
Argument,
|
|
361
|
-
'name' | 'required' | 'variadic' | 'usage' | 'defaultValue' | 'defaultValueDescription'
|
|
362
|
-
>;
|
|
325
|
+
type ArgumentOptionsBase = Omit<Argument, 'name' | 'required' | 'variadic' | 'usage' | 'defaultValue' | 'defaultValueDescription'>;
|
|
363
326
|
/** Base type for addArgument options, extended by specific required/optional and variadic/non-variadic argument option types */
|
|
364
327
|
type ExtendArgumentOptionsBase<T extends object = object> = Simplify<ArgumentOptionsBase & T>;
|
|
365
328
|
/** Required positional argument descriptor. Usage: `<name>` */
|
|
366
329
|
type RequiredArgumentOptions = ExtendArgumentOptionsBase;
|
|
367
330
|
/** Optional positional argument with string default. Usage: `[name]` */
|
|
368
331
|
type OptionalArgumentOptions = ExtendArgumentOptionsBase<{
|
|
369
|
-
|
|
370
|
-
|
|
332
|
+
defaultValue?: string;
|
|
333
|
+
defaultValueDescription?: string;
|
|
371
334
|
}>;
|
|
372
335
|
/** Optional positional argument with required string default. Usage: `[name]` */
|
|
373
|
-
type OptionalArgumentOptionsWithDefaultValue = SetFieldType<
|
|
374
|
-
SetRequired<OptionalArgumentOptions, 'defaultValue'>,
|
|
375
|
-
'defaultValue',
|
|
376
|
-
string
|
|
377
|
-
>;
|
|
336
|
+
type OptionalArgumentOptionsWithDefaultValue = SetFieldType<SetRequired<OptionalArgumentOptions, 'defaultValue'>, 'defaultValue', string>;
|
|
378
337
|
/** Required variadic argument accepting variadic values. Usage: `<name...>` */
|
|
379
338
|
type RequiredVariadicArgumentOptions = ExtendArgumentOptionsBase;
|
|
380
339
|
/** Optional variadic argument with array default. Usage: `[name...]` */
|
|
381
340
|
type OptionalVariadicArgumentOptions = ExtendArgumentOptionsBase<{
|
|
382
|
-
|
|
383
|
-
|
|
341
|
+
defaultValue?: string[];
|
|
342
|
+
defaultValueDescription?: string;
|
|
384
343
|
}>;
|
|
385
344
|
/** Union of all addArgument options types */
|
|
386
|
-
type ArgumentOptions = AllUnionFields<
|
|
387
|
-
| RequiredArgumentOptions
|
|
388
|
-
| OptionalArgumentOptions
|
|
389
|
-
| OptionalArgumentOptionsWithDefaultValue
|
|
390
|
-
| RequiredVariadicArgumentOptions
|
|
391
|
-
| OptionalVariadicArgumentOptions
|
|
392
|
-
>;
|
|
345
|
+
type ArgumentOptions = AllUnionFields<RequiredArgumentOptions | OptionalArgumentOptions | OptionalArgumentOptionsWithDefaultValue | RequiredVariadicArgumentOptions | OptionalVariadicArgumentOptions>;
|
|
393
346
|
/** Helper type for extracting argument name from usage pattern */
|
|
394
347
|
type InferAddedArgumentType<Opts> = Opts extends {
|
|
395
|
-
|
|
396
|
-
}
|
|
397
|
-
? C[number]
|
|
398
|
-
: string;
|
|
348
|
+
choices: infer C extends string[];
|
|
349
|
+
} ? C[number] : string;
|
|
399
350
|
/** Union of all option usage pattern types */
|
|
400
|
-
type OptionUsage<Long extends string> =
|
|
401
|
-
| `-${string}, --${Long}`
|
|
402
|
-
| `-${string}, --${Long} <${string}>`
|
|
403
|
-
| `-${string}, --${Long} [${string}]`
|
|
404
|
-
| `-${string}, --${Long} <${string}...>`
|
|
405
|
-
| `-${string}, --${Long} [${string}...]`;
|
|
351
|
+
type OptionUsage<Long extends string> = `-${string}, --${Long}` | `-${string}, --${Long} <${string}>` | `-${string}, --${Long} [${string}]` | `-${string}, --${Long} <${string}...>` | `-${string}, --${Long} [${string}...]`;
|
|
406
352
|
/** Base type for addOption options, extended by specific boolean/string and required/optional and variadic/non-variadic option types */
|
|
407
|
-
type OptionOptionsBase = Omit<
|
|
408
|
-
Option,
|
|
409
|
-
'name' | 'required' | 'variadic' | 'type' | 'argName' | 'short' | 'long' | 'flags'
|
|
410
|
-
>;
|
|
353
|
+
type OptionOptionsBase = Omit<Option, 'name' | 'required' | 'variadic' | 'type' | 'argName' | 'short' | 'long' | 'flags'>;
|
|
411
354
|
/** Helper type to extend base addOption options with specific fields for different option types */
|
|
412
355
|
type ExtendAddOptionOptionsBase<T extends object = object> = Simplify<OptionOptionsBase & T>;
|
|
413
356
|
/** Boolean flag option. Usage: `-v, --verbose` */
|
|
414
357
|
type BooleanOptionOptions = ExtendAddOptionOptionsBase<{
|
|
415
|
-
|
|
416
|
-
|
|
358
|
+
defaultValue?: boolean;
|
|
359
|
+
defaultValueDescription?: string;
|
|
417
360
|
}>;
|
|
418
361
|
/** Required string option. Usage: `-f, --file <path>` */
|
|
419
362
|
type RequiredOptionOptions = ExtendAddOptionOptionsBase<{
|
|
420
|
-
|
|
363
|
+
env?: undefined;
|
|
421
364
|
}>;
|
|
422
365
|
/** Optional string option with default. Usage: `-o, --output [path]` */
|
|
423
366
|
type OptionalOptionOptions = ExtendAddOptionOptionsBase<{
|
|
424
|
-
|
|
425
|
-
|
|
367
|
+
defaultValue?: string;
|
|
368
|
+
defaultValueDescription?: string;
|
|
426
369
|
}>;
|
|
427
370
|
/** Required option accepting variadic values. Usage: `-i, --include <patterns...>` */
|
|
428
371
|
type RequiredVariadicOptionOptions = ExtendAddOptionOptionsBase<{
|
|
429
|
-
|
|
372
|
+
env?: undefined;
|
|
430
373
|
}>;
|
|
431
374
|
/** Optional option accepting variadic values with defaults. Usage: `-e, --exclude [patterns...]` */
|
|
432
375
|
type OptionalVariadicOptionOptions = ExtendAddOptionOptionsBase<{
|
|
433
|
-
|
|
434
|
-
|
|
376
|
+
defaultValue?: string[];
|
|
377
|
+
defaultValueDescription?: string;
|
|
435
378
|
}>;
|
|
436
379
|
/** Union of all addOption options types */
|
|
437
|
-
type OptionOptions = AllUnionFields<
|
|
438
|
-
| BooleanOptionOptions
|
|
439
|
-
| RequiredOptionOptions
|
|
440
|
-
| OptionalOptionOptions
|
|
441
|
-
| RequiredVariadicOptionOptions
|
|
442
|
-
| OptionalVariadicOptionOptions
|
|
443
|
-
>;
|
|
380
|
+
type OptionOptions = AllUnionFields<BooleanOptionOptions | RequiredOptionOptions | OptionalOptionOptions | RequiredVariadicOptionOptions | OptionalVariadicOptionOptions>;
|
|
444
381
|
/** Helper type to infer the resulting Command type after adding an option with specific options */
|
|
445
|
-
type InferAddOptionResult<
|
|
446
|
-
A extends Arguments,
|
|
447
|
-
O extends Options,
|
|
448
|
-
NewOptions extends Options,
|
|
449
|
-
Subs extends SubCommands,
|
|
450
|
-
> = Command<A, Simplify<O & NewOptions>, Subs>;
|
|
382
|
+
type InferAddOptionResult<A extends Arguments, O extends Options, NewOptions extends Options, Subs extends SubCommands> = Command<A, Simplify<O & NewOptions>, Subs>;
|
|
451
383
|
|
|
452
384
|
/**
|
|
453
385
|
* This is a fork of the Help class from the 'commander' npm package. The Help class method names as well as the
|
|
@@ -455,395 +387,295 @@ type InferAddOptionResult<
|
|
|
455
387
|
* custom adaptations, @see ICommand
|
|
456
388
|
*/
|
|
457
389
|
declare class Help implements IHelp {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
/**
|
|
626
|
-
* Generate the built-in help text.
|
|
627
|
-
*/
|
|
628
|
-
render(): string;
|
|
390
|
+
protected readonly cmd: ICommand;
|
|
391
|
+
/** output helpWidth, long lines are wrapped to fit */
|
|
392
|
+
helpWidth: number;
|
|
393
|
+
minWidthToWrap: number;
|
|
394
|
+
sortSubcommands: boolean;
|
|
395
|
+
sortOptions: boolean;
|
|
396
|
+
usageDisplayOptionsAs: string;
|
|
397
|
+
usageDisplaySubcommandAs: string;
|
|
398
|
+
constructor(cmd: ICommand);
|
|
399
|
+
/**
|
|
400
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
401
|
+
*/
|
|
402
|
+
visibleCommands(): ICommand[];
|
|
403
|
+
/**
|
|
404
|
+
* Compare options for sort.
|
|
405
|
+
*/
|
|
406
|
+
compareOptions(a: Option, b: Option): number;
|
|
407
|
+
/**
|
|
408
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
409
|
+
*/
|
|
410
|
+
visibleOptions(): Option[];
|
|
411
|
+
/**
|
|
412
|
+
* Get an array of the arguments if any have a description.
|
|
413
|
+
*/
|
|
414
|
+
visibleArguments(): Argument[];
|
|
415
|
+
/**
|
|
416
|
+
* Get the command term to show in the list of subcommands.
|
|
417
|
+
*/
|
|
418
|
+
subcommandTerm(sub: ICommand): string;
|
|
419
|
+
/**
|
|
420
|
+
* Get the option term to show in the list of options.
|
|
421
|
+
*/
|
|
422
|
+
optionTerm(option: Option): string;
|
|
423
|
+
/**
|
|
424
|
+
* Get the argument term to show in the list of arguments.
|
|
425
|
+
*/
|
|
426
|
+
argumentTerm(argument: Argument): string;
|
|
427
|
+
/**
|
|
428
|
+
* Get the longest subcommand primary alias length.
|
|
429
|
+
*/
|
|
430
|
+
longestSubcommandAliasLength(): number;
|
|
431
|
+
/**
|
|
432
|
+
* Get the longest subcommand term length.
|
|
433
|
+
*/
|
|
434
|
+
longestSubcommandTermLength(): number;
|
|
435
|
+
/**
|
|
436
|
+
* Get the longest option term length.
|
|
437
|
+
*/
|
|
438
|
+
longestOptionTermLength(): number;
|
|
439
|
+
/**
|
|
440
|
+
* Get the longest argument term length.
|
|
441
|
+
*/
|
|
442
|
+
longestArgumentTermLength(): number;
|
|
443
|
+
/**
|
|
444
|
+
* Get the command usage to be displayed at the top of the built-in help.
|
|
445
|
+
*/
|
|
446
|
+
commandUsage(): string;
|
|
447
|
+
/**
|
|
448
|
+
* Get the description for the command.
|
|
449
|
+
*/
|
|
450
|
+
commandDescription(): string;
|
|
451
|
+
/**
|
|
452
|
+
* Get the subcommand summary to show in the list of subcommands.
|
|
453
|
+
* (Fallback to description for backwards compatibility.)
|
|
454
|
+
*/
|
|
455
|
+
subcommandDescription(sub: ICommand): string;
|
|
456
|
+
/**
|
|
457
|
+
* Get the option description to show in the list of options.
|
|
458
|
+
*/
|
|
459
|
+
optionDescription(option: Option): string;
|
|
460
|
+
/**
|
|
461
|
+
* Get the argument description to show in the list of arguments.
|
|
462
|
+
*/
|
|
463
|
+
argumentDescription(argument: Argument): string;
|
|
464
|
+
/**
|
|
465
|
+
* Format a list of items, given a heading and an array of formatted items.
|
|
466
|
+
*/
|
|
467
|
+
formatItemList(heading: string, items: string[]): string[];
|
|
468
|
+
/**
|
|
469
|
+
* Group items by their help group heading.
|
|
470
|
+
*/
|
|
471
|
+
groupItems<T extends ICommand | Option>(unsortedItems: T[], visibleItems: T[], getGroup: (item: T) => string): Map<string, T[]>;
|
|
472
|
+
/**
|
|
473
|
+
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
474
|
+
*/
|
|
475
|
+
displayWidth(str: string): number;
|
|
476
|
+
/**
|
|
477
|
+
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
478
|
+
*/
|
|
479
|
+
styleTitle(str: string): string;
|
|
480
|
+
/**
|
|
481
|
+
* Style the usage line for displaying in the help. Applies specific styling to different parts like options, commands, and arguments.
|
|
482
|
+
*/
|
|
483
|
+
styleUsage(str: string): string;
|
|
484
|
+
/**
|
|
485
|
+
* Style command descriptions for display in help output.
|
|
486
|
+
*/
|
|
487
|
+
styleCommandDescription(str: string): string;
|
|
488
|
+
/**
|
|
489
|
+
* Style option descriptions for display in help output.
|
|
490
|
+
*/
|
|
491
|
+
styleOptionDescription(str: string): string;
|
|
492
|
+
/**
|
|
493
|
+
* Style subcommand descriptions for display in help output.
|
|
494
|
+
*/
|
|
495
|
+
styleSubcommandDescription(str: string): string;
|
|
496
|
+
/**
|
|
497
|
+
* Style argument descriptions for display in help output.
|
|
498
|
+
*/
|
|
499
|
+
styleArgumentDescription(str: string): string;
|
|
500
|
+
/**
|
|
501
|
+
* Base style used by descriptions. Override in subclass to apply custom formatting.
|
|
502
|
+
*/
|
|
503
|
+
styleDescriptionText(str: string): string;
|
|
504
|
+
/**
|
|
505
|
+
* Style option terms (flags) for display in help output.
|
|
506
|
+
*/
|
|
507
|
+
styleOptionTerm(str: string): string;
|
|
508
|
+
/**
|
|
509
|
+
* Style subcommand terms for display in help output. Applies specific styling to different parts like options and arguments.
|
|
510
|
+
*/
|
|
511
|
+
styleSubcommandTerm(str: string): string;
|
|
512
|
+
/**
|
|
513
|
+
* Style argument terms for display in help output.
|
|
514
|
+
*/
|
|
515
|
+
styleArgumentTerm(str: string): string;
|
|
516
|
+
/**
|
|
517
|
+
* Base style used in terms and usage for options. Override in subclass to apply custom formatting.
|
|
518
|
+
*/
|
|
519
|
+
styleOptionText(str: string): string;
|
|
520
|
+
/**
|
|
521
|
+
* Base style used in terms and usage for arguments. Override in subclass to apply custom formatting.
|
|
522
|
+
*/
|
|
523
|
+
styleArgumentText(str: string): string;
|
|
524
|
+
/**
|
|
525
|
+
* Base style used in terms and usage for subcommands. Override in subclass to apply custom formatting.
|
|
526
|
+
*/
|
|
527
|
+
styleSubcommandText(str: string): string;
|
|
528
|
+
/**
|
|
529
|
+
* Base style used in terms and usage for commands. Override in subclass to apply custom formatting.
|
|
530
|
+
*/
|
|
531
|
+
styleCommandText(str: string): string;
|
|
532
|
+
/**
|
|
533
|
+
* Calculate the pad width from the maximum term length.
|
|
534
|
+
*/
|
|
535
|
+
padWidth(): number;
|
|
536
|
+
/**
|
|
537
|
+
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
538
|
+
*/
|
|
539
|
+
preformatted(str: string): boolean;
|
|
540
|
+
/**
|
|
541
|
+
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
542
|
+
*
|
|
543
|
+
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
544
|
+
* TTT DDD DDDD
|
|
545
|
+
* DD DDD
|
|
546
|
+
*/
|
|
547
|
+
formatItem(term: string, termWidth: number, description: string): string;
|
|
548
|
+
/**
|
|
549
|
+
* Wrap a string at whitespace, preserving existing line breaks.
|
|
550
|
+
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
551
|
+
*/
|
|
552
|
+
boxWrap(str: string, width: number): string;
|
|
553
|
+
/**
|
|
554
|
+
* Generate the built-in help text.
|
|
555
|
+
*/
|
|
556
|
+
render(): string;
|
|
629
557
|
}
|
|
630
558
|
|
|
631
559
|
/**
|
|
632
560
|
* a type-safe CLI composer that can parse argv and generate help without execution coupling.
|
|
633
561
|
*/
|
|
634
|
-
declare class Command<
|
|
635
|
-
A extends Arguments = [],
|
|
636
|
-
O extends Options = {
|
|
562
|
+
declare class Command<A extends Arguments = [], O extends Options = {
|
|
637
563
|
help?: boolean;
|
|
638
564
|
debug?: boolean;
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
name
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
(SubCommands extends Subs ? {} : Subs) & {
|
|
711
|
-
[K in Name]: Sub;
|
|
712
|
-
}
|
|
713
|
-
>;
|
|
714
|
-
/** add required variadic argument, eg.: `<name...>` */
|
|
715
|
-
addArgument<const Opts extends RequiredVariadicArgumentOptions>(
|
|
716
|
-
usage: AllowedArgumentUsage<this, `<${string}...>`>,
|
|
717
|
-
options?: Opts,
|
|
718
|
-
): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
|
|
719
|
-
/** add required argument, eg.: `<name>` */
|
|
720
|
-
addArgument<const Opts extends RequiredArgumentOptions>(
|
|
721
|
-
usage: AllowedArgumentUsage<this, `<${string}>`>,
|
|
722
|
-
options?: Opts,
|
|
723
|
-
): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
|
|
724
|
-
/** add optional variadic argument with defaults, eg.: `[name...]` */
|
|
725
|
-
addArgument<const Opts extends OptionalVariadicArgumentOptions>(
|
|
726
|
-
usage: AllowedArgumentUsage<this, `[${string}...]`>,
|
|
727
|
-
options?: Opts,
|
|
728
|
-
): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
|
|
729
|
-
/** add optional argument with default, eg.: `[name]` */
|
|
730
|
-
addArgument<const Opts extends OptionalArgumentOptionsWithDefaultValue>(
|
|
731
|
-
usage: AllowedArgumentUsage<this, `[${string}]`>,
|
|
732
|
-
options: Opts,
|
|
733
|
-
): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
|
|
734
|
-
/** add optional argument, eg.: `[name]` */
|
|
735
|
-
addArgument<const Opts extends OptionalArgumentOptions>(
|
|
736
|
-
usage: AllowedArgumentUsage<this, `[${string}]`>,
|
|
737
|
-
options?: Opts,
|
|
738
|
-
): Command<[...A, InferAddedArgumentType<Opts> | undefined], O, Subs>;
|
|
739
|
-
/** add optional string option, eg.: `-o, --output [path]` */
|
|
740
|
-
addOption<Long extends string>(
|
|
741
|
-
flags: `-${string}, --${Long} [${string}]`,
|
|
742
|
-
options?: SetFieldType<OptionalOptionOptions, 'defaultValue', undefined | never>,
|
|
743
|
-
): Command<
|
|
744
|
-
A,
|
|
745
|
-
Simplify<
|
|
746
|
-
{
|
|
565
|
+
}, Subs extends SubCommands = SubCommands> implements ICommand {
|
|
566
|
+
/** parent command in the hierarchy, undefined for root command */
|
|
567
|
+
parent?: Command<Arguments, Options & O>;
|
|
568
|
+
/** the command name used to invoke it */
|
|
569
|
+
name: string;
|
|
570
|
+
/** semantic version string displayed by --version flag */
|
|
571
|
+
version?: string;
|
|
572
|
+
/** alternative names for invoking this command */
|
|
573
|
+
aliases: string[];
|
|
574
|
+
/** brief one-line description shown in command lists */
|
|
575
|
+
summary?: string;
|
|
576
|
+
/** full description displayed in help text */
|
|
577
|
+
description: string;
|
|
578
|
+
/** whether to exclude from help listings */
|
|
579
|
+
hidden?: boolean;
|
|
580
|
+
/** category for organizing related commands in help output */
|
|
581
|
+
group?: string;
|
|
582
|
+
/** positional arguments this command accepts */
|
|
583
|
+
arguments: Argument[];
|
|
584
|
+
/** cLI options (flags) this command recognizes */
|
|
585
|
+
options: Option[];
|
|
586
|
+
/** subcommands registered with this command */
|
|
587
|
+
commands: Subs;
|
|
588
|
+
/** main action handler executed when command is invoked */
|
|
589
|
+
protected action?: ActionHandler<A, O, Subs>;
|
|
590
|
+
/** option-driven actions (e.g., --help, --version) executed when their conditions match */
|
|
591
|
+
protected hooks: HookDefinition<Arguments, Options & O>[];
|
|
592
|
+
constructor(name: string, parent?: ICommand);
|
|
593
|
+
protected get help(): Help;
|
|
594
|
+
/** configure how the help is rendered */
|
|
595
|
+
helpConfiguration(cb?: (help: Help) => void): this;
|
|
596
|
+
/** renders formatted help text using provided help definition */
|
|
597
|
+
renderHelp(config?: {
|
|
598
|
+
noColor?: boolean;
|
|
599
|
+
}): string;
|
|
600
|
+
/** sets the command name */
|
|
601
|
+
setName(name: string): void;
|
|
602
|
+
/** sets command aliases, flattening nested arrays */
|
|
603
|
+
setAliases(...aliases: (string | string[])[]): this;
|
|
604
|
+
/** adds aliases to existing ones */
|
|
605
|
+
addAliases(...aliases: (string | string[])[]): this;
|
|
606
|
+
/** sets the command version */
|
|
607
|
+
setVersion(version: string): InferAddOptionResult<A, O, {
|
|
608
|
+
version?: boolean;
|
|
609
|
+
}, Subs>;
|
|
610
|
+
/** sets the command summary */
|
|
611
|
+
setSummary(summary?: string): this;
|
|
612
|
+
/** sets command description, joining variadic lines */
|
|
613
|
+
setDescription(...lines: string[]): this;
|
|
614
|
+
/** sets whether command is hidden from help */
|
|
615
|
+
setHidden(hidden?: boolean | undefined): this;
|
|
616
|
+
/** sets the command group for help organization */
|
|
617
|
+
setGroup(group?: string): this;
|
|
618
|
+
/** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
619
|
+
command<Name extends string, Sub extends Command<any, any, any> = Command<[], O, {}>>(name: Name, cb?: (cmd: Command<[], O, {}>, parent: this) => Sub): Sub;
|
|
620
|
+
/** add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
621
|
+
addCommand<Name extends string, Sub extends Command<any, any, any> = Command<[], O, {}>>(name: Name, cb: (cmd: Command<[], O, {}>, parent: this) => Sub): Command<A, O, (SubCommands extends Subs ? {} : Subs) & {
|
|
622
|
+
[K in Name]: Sub;
|
|
623
|
+
}>;
|
|
624
|
+
/** add required variadic argument, eg.: `<name...>` */
|
|
625
|
+
addArgument<const Opts extends RequiredVariadicArgumentOptions>(usage: AllowedArgumentUsage<this, `<${string}...>`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
|
|
626
|
+
/** add required argument, eg.: `<name>` */
|
|
627
|
+
addArgument<const Opts extends RequiredArgumentOptions>(usage: AllowedArgumentUsage<this, `<${string}>`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
|
|
628
|
+
/** add optional variadic argument with defaults, eg.: `[name...]` */
|
|
629
|
+
addArgument<const Opts extends OptionalVariadicArgumentOptions>(usage: AllowedArgumentUsage<this, `[${string}...]`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
|
|
630
|
+
/** add optional argument with default, eg.: `[name]` */
|
|
631
|
+
addArgument<const Opts extends OptionalArgumentOptionsWithDefaultValue>(usage: AllowedArgumentUsage<this, `[${string}]`>, options: Opts): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
|
|
632
|
+
/** add optional argument, eg.: `[name]` */
|
|
633
|
+
addArgument<const Opts extends OptionalArgumentOptions>(usage: AllowedArgumentUsage<this, `[${string}]`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts> | undefined], O, Subs>;
|
|
634
|
+
/** add optional string option, eg.: `-o, --output [path]` */
|
|
635
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}]`, options?: SetFieldType<OptionalOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
|
|
747
636
|
[K in CamelCase<Long>]?: string;
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
>;
|
|
752
|
-
/** add optional string option with default, eg.: `-o, --output [path]` */
|
|
753
|
-
addOption<Long extends string>(
|
|
754
|
-
flags: `-${string}, --${Long} [${string}]`,
|
|
755
|
-
options: SetFieldType<SetRequired<OptionalOptionOptions, 'defaultValue'>, 'defaultValue', string>,
|
|
756
|
-
): Command<
|
|
757
|
-
A,
|
|
758
|
-
Simplify<
|
|
759
|
-
{
|
|
637
|
+
} & O>, Subs>;
|
|
638
|
+
/** add optional string option with default, eg.: `-o, --output [path]` */
|
|
639
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}]`, options: SetFieldType<SetRequired<OptionalOptionOptions, 'defaultValue'>, 'defaultValue', string>): Command<A, Simplify<{
|
|
760
640
|
[K in CamelCase<Long>]: string;
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
>;
|
|
765
|
-
/** add required variadic option, eg.: `-i, --include <patterns...>` */
|
|
766
|
-
addOption<Long extends string>(
|
|
767
|
-
flags: `-${string}, --${Long} <${string}...>`,
|
|
768
|
-
options?: RequiredVariadicOptionOptions,
|
|
769
|
-
): Command<
|
|
770
|
-
A,
|
|
771
|
-
Simplify<
|
|
772
|
-
{
|
|
641
|
+
} & O>, Subs>;
|
|
642
|
+
/** add required variadic option, eg.: `-i, --include <patterns...>` */
|
|
643
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} <${string}...>`, options?: RequiredVariadicOptionOptions): Command<A, Simplify<{
|
|
773
644
|
[K in CamelCase<Long>]: string[];
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
>;
|
|
778
|
-
/** add optional variadic option with defaults, eg.: `-e, --exclude [patterns...]` */
|
|
779
|
-
addOption<Long extends string>(
|
|
780
|
-
flags: `-${string}, --${Long} [${string}...]`,
|
|
781
|
-
options?: OptionalVariadicOptionOptions,
|
|
782
|
-
): Command<
|
|
783
|
-
A,
|
|
784
|
-
Simplify<
|
|
785
|
-
{
|
|
645
|
+
} & O>, Subs>;
|
|
646
|
+
/** add optional variadic option with defaults, eg.: `-e, --exclude [patterns...]` */
|
|
647
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}...]`, options?: OptionalVariadicOptionOptions): Command<A, Simplify<{
|
|
786
648
|
[K in CamelCase<Long>]: string[];
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
>;
|
|
791
|
-
/** add required string option, eg.: `-f, --file <path>` */
|
|
792
|
-
addOption<Long extends string>(
|
|
793
|
-
flags: `-${string}, --${Long} <${string}>`,
|
|
794
|
-
options?: RequiredOptionOptions,
|
|
795
|
-
): Command<
|
|
796
|
-
A,
|
|
797
|
-
Simplify<
|
|
798
|
-
{
|
|
649
|
+
} & O>, Subs>;
|
|
650
|
+
/** add required string option, eg.: `-f, --file <path>` */
|
|
651
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} <${string}>`, options?: RequiredOptionOptions): Command<A, Simplify<{
|
|
799
652
|
[K in CamelCase<Long>]: string;
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
>;
|
|
804
|
-
/** add boolean flag option with default, eg.: `-v, --verbose` */
|
|
805
|
-
addOption<Long extends string>(
|
|
806
|
-
flags: `-${string}, --${Long}`,
|
|
807
|
-
options: SetFieldType<SetRequired<BooleanOptionOptions, 'defaultValue'>, 'defaultValue', boolean>,
|
|
808
|
-
): Command<
|
|
809
|
-
A,
|
|
810
|
-
Simplify<
|
|
811
|
-
{
|
|
653
|
+
} & O>, Subs>;
|
|
654
|
+
/** add boolean flag option with default, eg.: `-v, --verbose` */
|
|
655
|
+
addOption<Long extends string>(flags: `-${string}, --${Long}`, options: SetFieldType<SetRequired<BooleanOptionOptions, 'defaultValue'>, 'defaultValue', boolean>): Command<A, Simplify<{
|
|
812
656
|
[K in CamelCase<Long>]: boolean;
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
>;
|
|
817
|
-
/** add boolean flag option, eg.: `-v, --verbose` */
|
|
818
|
-
addOption<Long extends string>(
|
|
819
|
-
flags: `-${string}, --${Long}`,
|
|
820
|
-
options?: SetFieldType<BooleanOptionOptions, 'defaultValue', undefined | never>,
|
|
821
|
-
): Command<
|
|
822
|
-
A,
|
|
823
|
-
Simplify<
|
|
824
|
-
{
|
|
657
|
+
} & O>, Subs>;
|
|
658
|
+
/** add boolean flag option, eg.: `-v, --verbose` */
|
|
659
|
+
addOption<Long extends string>(flags: `-${string}, --${Long}`, options?: SetFieldType<BooleanOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
|
|
825
660
|
[K in CamelCase<Long>]?: boolean;
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
setAction(fn: ActionHandler<A, O, Subs>): this;
|
|
845
|
-
/** returns a new Command instance. Override this method in subclasses. */
|
|
846
|
-
protected createSubcommand(name: string): Command<[], O, {}>;
|
|
661
|
+
} & O>, Subs>;
|
|
662
|
+
/**
|
|
663
|
+
* register an action to be invoked when an option is set to true or string value.
|
|
664
|
+
*
|
|
665
|
+
* Hooks execute in addition to or instead of the main action handler,
|
|
666
|
+
* allowing for option-driven behavior. For example, `--help` and `--version`
|
|
667
|
+
* are implemented as hooks.
|
|
668
|
+
*/
|
|
669
|
+
addOptionHook(optionName: keyof O, action: HookActionHandler<Arguments, O>): this;
|
|
670
|
+
/** parses command-line arguments with subcommand support and type-safe validation. */
|
|
671
|
+
parseArgv(argv?: string[]): ParseArgvResult<Arguments, Options & O>;
|
|
672
|
+
/**
|
|
673
|
+
* sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
|
|
674
|
+
* The handler receives parsed arguments and options with correct typings.
|
|
675
|
+
*/
|
|
676
|
+
setAction(fn: ActionHandler<A, O, Subs>): this;
|
|
677
|
+
/** returns a new Command instance. Override this method in subclasses. */
|
|
678
|
+
protected createSubcommand(name: string): Command<[], O, {}>;
|
|
847
679
|
}
|
|
848
680
|
|
|
849
681
|
/**
|
|
@@ -869,55 +701,11 @@ declare function getCommandAndAncestors<C extends ICommand>(cmd: C): [typeof cmd
|
|
|
869
701
|
/**
|
|
870
702
|
* Parses option flags string into its components
|
|
871
703
|
*/
|
|
872
|
-
declare function parseOptionFlags<Long extends string>(
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
name: CamelCase<Long>;
|
|
878
|
-
argName: string | undefined;
|
|
704
|
+
declare function parseOptionFlags<Long extends string>(flags: OptionUsage<Long>): {
|
|
705
|
+
short: string;
|
|
706
|
+
long: Long;
|
|
707
|
+
name: CamelCase<Long>;
|
|
708
|
+
argName: string | undefined;
|
|
879
709
|
};
|
|
880
710
|
|
|
881
|
-
export {
|
|
882
|
-
type ActionHandler,
|
|
883
|
-
type AllowedArgumentUsage,
|
|
884
|
-
type Argument,
|
|
885
|
-
type ArgumentOptions,
|
|
886
|
-
type ArgumentUsage,
|
|
887
|
-
type Arguments,
|
|
888
|
-
type BooleanOptionOptions,
|
|
889
|
-
Command,
|
|
890
|
-
Help,
|
|
891
|
-
type HookActionHandler,
|
|
892
|
-
type HookDefinition,
|
|
893
|
-
type HookPredicate,
|
|
894
|
-
type ICommand,
|
|
895
|
-
type IHelp,
|
|
896
|
-
type InferAddOptionResult,
|
|
897
|
-
type InferAddedArgumentType,
|
|
898
|
-
type Logger,
|
|
899
|
-
type Option,
|
|
900
|
-
type OptionOptions,
|
|
901
|
-
type OptionUsage,
|
|
902
|
-
type OptionalArgumentOptions,
|
|
903
|
-
type OptionalArgumentOptionsWithDefaultValue,
|
|
904
|
-
type OptionalArgumentUsage,
|
|
905
|
-
type OptionalOptionOptions,
|
|
906
|
-
type OptionalVariadicArgumentOptions,
|
|
907
|
-
type OptionalVariadicArgumentUsage,
|
|
908
|
-
type OptionalVariadicOptionOptions,
|
|
909
|
-
type Options,
|
|
910
|
-
type ParseArgvResult,
|
|
911
|
-
type RequiredArgumentOptions,
|
|
912
|
-
type RequiredArgumentUsage,
|
|
913
|
-
type RequiredOptionOptions,
|
|
914
|
-
type RequiredVariadicArgumentOptions,
|
|
915
|
-
type RequiredVariadicArgumentUsage,
|
|
916
|
-
type RequiredVariadicOptionOptions,
|
|
917
|
-
type SubCommands,
|
|
918
|
-
findCommand,
|
|
919
|
-
findOption,
|
|
920
|
-
getCommandAncestors,
|
|
921
|
-
getCommandAndAncestors,
|
|
922
|
-
parseOptionFlags,
|
|
923
|
-
};
|
|
711
|
+
export { type ActionHandler, type AllowedArgumentUsage, type Argument, type ArgumentOptions, type ArgumentUsage, type Arguments, type BooleanOptionOptions, Command, Help, type HookActionHandler, type HookDefinition, type HookPredicate, type ICommand, type IHelp, type InferAddOptionResult, type InferAddedArgumentType, type Logger, type Option, type OptionOptions, type OptionUsage, type OptionalArgumentOptions, type OptionalArgumentOptionsWithDefaultValue, type OptionalArgumentUsage, type OptionalOptionOptions, type OptionalVariadicArgumentOptions, type OptionalVariadicArgumentUsage, type OptionalVariadicOptionOptions, type Options, type ParseArgvResult, type RequiredArgumentOptions, type RequiredArgumentUsage, type RequiredOptionOptions, type RequiredVariadicArgumentOptions, type RequiredVariadicArgumentUsage, type RequiredVariadicOptionOptions, type SubCommands, findCommand, findOption, getCommandAncestors, getCommandAndAncestors, parseOptionFlags };
|