@bemoje/cli 2.1.4 → 2.1.6

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