@bemoje/cli 1.1.1 → 2.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 +27 -1
- package/index.mjs +1352 -0
- package/index.mjs.map +7 -0
- package/lib/Command.d.ts +97 -262
- package/lib/Help.d.ts +37 -83
- package/lib/helpers/findCommand.d.ts +6 -0
- package/lib/helpers/findOption.d.ts +5 -0
- package/lib/helpers/getCommandAncestors.d.ts +5 -0
- package/lib/helpers/getCommandAndAncestors.d.ts +5 -0
- package/lib/helpers/parseOptionFlags.d.ts +11 -0
- package/lib/internal/collectVariadicOptionValues.d.ts +7 -0
- package/lib/internal/mergeOptionDefaults.d.ts +3 -0
- package/lib/internal/normalizeArgv.d.ts +3 -0
- package/lib/internal/resolveArguments.d.ts +3 -0
- package/lib/internal/validateParsed.d.ts +3 -0
- package/lib/types.d.ts +383 -0
- package/package.json +35 -29
- package/LICENSE +0 -21
- package/README.md +0 -246
- package/index.js +0 -3
- package/lib/Command.js +0 -421
- package/lib/Help.js +0 -474
package/lib/Command.d.ts
CHANGED
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import type { CamelCase, SetFieldType, Simplify, SetRequired } from 'type-fest';
|
|
2
|
+
import { Help } from './Help';
|
|
3
|
+
import type { Arguments, Argument, ICommand, Option, Options, SubCommands } from './types';
|
|
4
|
+
import type { ActionHandler, BooleanOptionOptions, AllowedArgumentUsage, InferAddedArgumentType, InferAddOptionResult, OptionalArgumentOptions, OptionalArgumentOptionsWithDefaultValue, OptionalOptionOptions, OptionalVariadicArgumentOptions, OptionalVariadicOptionOptions, RequiredArgumentOptions, RequiredOptionOptions, RequiredVariadicArgumentOptions, RequiredVariadicOptionOptions, ParseArgvResult, HookDefinition, HookActionHandler } from './types';
|
|
4
5
|
/**
|
|
5
|
-
*
|
|
6
|
-
* Enforces CLI argument ordering rules and provides structured parsing results.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* const cmd = new Command('myapp')
|
|
11
|
-
* .addArgument('<input>', 'input file')
|
|
12
|
-
* .addArgument('[output]', 'output file', 'out.txt')
|
|
13
|
-
* .addOption('-v, --verbose', 'verbose output')
|
|
14
|
-
* .addOption('-f, --format <type>', 'output format')
|
|
15
|
-
*
|
|
16
|
-
* cmd.parseArgv(['input.txt', '-v', '-f', 'json'])
|
|
17
|
-
* ```
|
|
6
|
+
* A type-safe CLI composer that can parse argv and generate help without execution coupling.
|
|
18
7
|
*/
|
|
19
|
-
export declare class Command
|
|
20
|
-
|
|
8
|
+
export declare class Command<A extends Arguments = [], O extends Options = {
|
|
9
|
+
help?: boolean;
|
|
10
|
+
debug?: boolean;
|
|
11
|
+
}, Subs extends SubCommands = SubCommands> implements ICommand {
|
|
12
|
+
/** Parent command in the hierarchy, undefined for root command */
|
|
13
|
+
parent?: Command<Arguments, Options & O>;
|
|
14
|
+
/** The command name used to invoke it */
|
|
21
15
|
name: string;
|
|
22
|
-
/**
|
|
16
|
+
/** Semantic version string displayed by --version flag */
|
|
23
17
|
version?: string;
|
|
24
|
-
/** Alternative names for this command */
|
|
18
|
+
/** Alternative names for invoking this command */
|
|
25
19
|
aliases: string[];
|
|
26
|
-
/** Brief
|
|
20
|
+
/** Brief one-line description shown in command lists */
|
|
27
21
|
summary?: string;
|
|
28
|
-
/** Full
|
|
22
|
+
/** Full description displayed in help text */
|
|
29
23
|
description: string;
|
|
30
|
-
/** Whether
|
|
24
|
+
/** Whether to exclude from help listings */
|
|
31
25
|
hidden?: boolean;
|
|
32
|
-
/**
|
|
26
|
+
/** Category for organizing related commands in help output */
|
|
33
27
|
group?: string;
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
constructor(name
|
|
28
|
+
/** Positional arguments this command accepts */
|
|
29
|
+
arguments: Argument[];
|
|
30
|
+
/** CLI options (flags) this command recognizes */
|
|
31
|
+
options: Option[];
|
|
32
|
+
/** Subcommands registered with this command */
|
|
33
|
+
commands: Subs;
|
|
34
|
+
/** Main action handler executed when command is invoked */
|
|
35
|
+
protected action?: ActionHandler<A, O, Subs>;
|
|
36
|
+
/** Option-driven actions (e.g., --help, --version) executed when their conditions match */
|
|
37
|
+
protected hooks: HookDefinition<Arguments, Options & O>[];
|
|
38
|
+
constructor(name: string, parent?: ICommand);
|
|
39
|
+
protected get help(): Help;
|
|
40
|
+
/** Configure how the help is rendered */
|
|
41
|
+
helpConfiguration(cb?: (help: Help) => void): this;
|
|
42
|
+
/** Renders formatted help text using provided help definition */
|
|
43
|
+
renderHelp(config?: {
|
|
44
|
+
noColor?: boolean;
|
|
45
|
+
}): string;
|
|
45
46
|
/** Sets the command name */
|
|
46
47
|
setName(name: string): void;
|
|
47
48
|
/** Sets command aliases, flattening nested arrays */
|
|
@@ -49,7 +50,9 @@ export declare class Command implements CommandDescriptor {
|
|
|
49
50
|
/** Adds aliases to existing ones */
|
|
50
51
|
addAliases(...aliases: (string | string[])[]): this;
|
|
51
52
|
/** Sets the command version */
|
|
52
|
-
setVersion(version
|
|
53
|
+
setVersion(version: string): InferAddOptionResult<A, O, {
|
|
54
|
+
version?: boolean;
|
|
55
|
+
}, Subs>;
|
|
53
56
|
/** Sets the command summary */
|
|
54
57
|
setSummary(summary?: string): this;
|
|
55
58
|
/** Sets command description, joining variadic lines */
|
|
@@ -57,234 +60,66 @@ export declare class Command implements CommandDescriptor {
|
|
|
57
60
|
/** Sets whether command is hidden from help */
|
|
58
61
|
setHidden(hidden?: boolean | undefined): this;
|
|
59
62
|
/** Sets the command group for help organization */
|
|
60
|
-
setGroup(group?:
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
|
|
69
|
-
/** Add required argument
|
|
70
|
-
addArgument(usage: `<${string}
|
|
71
|
-
/** Add optional argument with
|
|
72
|
-
addArgument(usage: `[${string}]
|
|
73
|
-
/** Add
|
|
74
|
-
addArgument(usage:
|
|
75
|
-
/** Add optional
|
|
76
|
-
addArgument(usage: `[${string}
|
|
77
|
-
/** Add
|
|
78
|
-
addOption(flags: `-${string}, --${
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
/** Add
|
|
82
|
-
addOption(flags: `-${string}, --${
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
/** Add
|
|
86
|
-
addOption(flags: `-${string}, --${
|
|
87
|
-
|
|
63
|
+
setGroup(group?: string): this;
|
|
64
|
+
/** Add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
65
|
+
command<Name extends string, Sub extends Command<any, any, any> = Command<[], O, {}>>(name: Name, cb?: (cmd: Command<[], O, {}>, parent: this) => Sub): Sub;
|
|
66
|
+
/** Add a subcommand and return the subcommand. All options are inherited by the subcommand. */
|
|
67
|
+
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) & {
|
|
68
|
+
[K in Name]: Sub;
|
|
69
|
+
}>;
|
|
70
|
+
/** Add required variadic argument, eg.: `<name...>` */
|
|
71
|
+
addArgument<const Opts extends RequiredVariadicArgumentOptions>(usage: AllowedArgumentUsage<this, `<${string}...>`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
|
|
72
|
+
/** Add required argument, eg.: `<name>` */
|
|
73
|
+
addArgument<const Opts extends RequiredArgumentOptions>(usage: AllowedArgumentUsage<this, `<${string}>`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
|
|
74
|
+
/** Add optional variadic argument with defaults, eg.: `[name...]` */
|
|
75
|
+
addArgument<const Opts extends OptionalVariadicArgumentOptions>(usage: AllowedArgumentUsage<this, `[${string}...]`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts>[]], O, Subs>;
|
|
76
|
+
/** Add optional argument with default, eg.: `[name]` */
|
|
77
|
+
addArgument<const Opts extends OptionalArgumentOptionsWithDefaultValue>(usage: AllowedArgumentUsage<this, `[${string}]`>, options: Opts): Command<[...A, InferAddedArgumentType<Opts>], O, Subs>;
|
|
78
|
+
/** Add optional argument, eg.: `[name]` */
|
|
79
|
+
addArgument<const Opts extends OptionalArgumentOptions>(usage: AllowedArgumentUsage<this, `[${string}]`>, options?: Opts): Command<[...A, InferAddedArgumentType<Opts> | undefined], O, Subs>;
|
|
80
|
+
/** Add optional string option, eg.: `-o, --output [path]` */
|
|
81
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}]`, options?: SetFieldType<OptionalOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
|
|
82
|
+
[K in CamelCase<Long>]?: string;
|
|
83
|
+
} & O>, Subs>;
|
|
84
|
+
/** Add optional string option with default, eg.: `-o, --output [path]` */
|
|
85
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}]`, options: SetFieldType<SetRequired<OptionalOptionOptions, 'defaultValue'>, 'defaultValue', string>): Command<A, Simplify<{
|
|
86
|
+
[K in CamelCase<Long>]: string;
|
|
87
|
+
} & O>, Subs>;
|
|
88
|
+
/** Add required variadic option, eg.: `-i, --include <patterns...>` */
|
|
89
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} <${string}...>`, options?: RequiredVariadicOptionOptions): Command<A, Simplify<{
|
|
90
|
+
[K in CamelCase<Long>]: string[];
|
|
91
|
+
} & O>, Subs>;
|
|
92
|
+
/** Add optional variadic option with defaults, eg.: `-e, --exclude [patterns...]` */
|
|
93
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} [${string}...]`, options?: OptionalVariadicOptionOptions): Command<A, Simplify<{
|
|
94
|
+
[K in CamelCase<Long>]: string[];
|
|
95
|
+
} & O>, Subs>;
|
|
96
|
+
/** Add required string option, eg.: `-f, --file <path>` */
|
|
97
|
+
addOption<Long extends string>(flags: `-${string}, --${Long} <${string}>`, options?: RequiredOptionOptions): Command<A, Simplify<{
|
|
98
|
+
[K in CamelCase<Long>]: string;
|
|
99
|
+
} & O>, Subs>;
|
|
100
|
+
/** Add boolean flag option with default, eg.: `-v, --verbose` */
|
|
101
|
+
addOption<Long extends string>(flags: `-${string}, --${Long}`, options: SetFieldType<SetRequired<BooleanOptionOptions, 'defaultValue'>, 'defaultValue', boolean>): Command<A, Simplify<{
|
|
102
|
+
[K in CamelCase<Long>]: boolean;
|
|
103
|
+
} & O>, Subs>;
|
|
104
|
+
/** Add boolean flag option, eg.: `-v, --verbose` */
|
|
105
|
+
addOption<Long extends string>(flags: `-${string}, --${Long}`, options?: SetFieldType<BooleanOptionOptions, 'defaultValue', undefined | never>): Command<A, Simplify<{
|
|
106
|
+
[K in CamelCase<Long>]?: boolean;
|
|
107
|
+
} & O>, Subs>;
|
|
88
108
|
/**
|
|
89
|
-
*
|
|
109
|
+
* Register an action to be invoked when an option is set to true or string value.
|
|
90
110
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* // { arguments: ['input.txt'], options: { verbose: true, format: 'json' } }
|
|
95
|
-
* ```
|
|
111
|
+
* Hooks execute in addition to or instead of the main action handler,
|
|
112
|
+
* allowing for option-driven behavior. For example, `--help` and `--version`
|
|
113
|
+
* are implemented as hooks.
|
|
96
114
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
renderHelp(help?: IHelp): string;
|
|
106
|
-
/** Validates CLI argument ordering */
|
|
107
|
-
protected assertNoOptionalOrVariadicArguments(): void;
|
|
108
|
-
/** Validates optional args don't follow variadic args */
|
|
109
|
-
protected assertNoVariadicArgument(): void;
|
|
110
|
-
/** Ensures only one variadic argument per command */
|
|
111
|
-
protected assertNoMultipleVariadicArguments(): void;
|
|
112
|
-
/** Ensures unique argument names across arguments and options */
|
|
113
|
-
protected assertArgumentNameNotInUse(name: string): void;
|
|
114
|
-
/** Validates option short names are single alphanumeric characters */
|
|
115
|
-
protected assertOptionShortNameIsValid(short: string): void;
|
|
116
|
-
/** Validates option short names are unique across command hierarchy */
|
|
117
|
-
protected assertOptionShortNameNotInUse(short: string): void;
|
|
118
|
-
/** Validates option names are unique across command hierarchy */
|
|
119
|
-
protected assertOptionNameNotInUse(name: string): void;
|
|
120
|
-
/** Returns command and all ancestor commands in hierarchy */
|
|
121
|
-
getCommandAndAncestors(): Command[];
|
|
122
|
-
/** Returns all ancestor commands excluding this command */
|
|
123
|
-
getAncestors(): Command[];
|
|
124
|
-
/** Returns all options from this command and ancestors */
|
|
125
|
-
getOptionsInclAncestors(): {
|
|
126
|
-
name: string;
|
|
127
|
-
long: string;
|
|
128
|
-
short: string;
|
|
129
|
-
required?: boolean;
|
|
130
|
-
type: "string" | "boolean";
|
|
131
|
-
optional?: boolean;
|
|
132
|
-
negate?: boolean;
|
|
133
|
-
hidden?: boolean;
|
|
134
|
-
description: string;
|
|
135
|
-
group?: string;
|
|
136
|
-
variadic?: boolean;
|
|
137
|
-
defaultValue?: string | boolean | string[];
|
|
138
|
-
flags: string;
|
|
139
|
-
defaultValueDescription?: string;
|
|
140
|
-
choices?: string[];
|
|
141
|
-
argName?: string;
|
|
142
|
-
env?: string;
|
|
143
|
-
}[];
|
|
144
|
-
/** Finds subcommand by name or alias */
|
|
145
|
-
findCommand(this: Command, name: string): Command;
|
|
146
|
-
/** Finds option by short or long name */
|
|
147
|
-
findOption(this: Command, arg: string): OptionDescriptor | undefined;
|
|
115
|
+
addOptionHook(optionName: keyof O, action: HookActionHandler<Arguments, O>): this;
|
|
116
|
+
/** Parses command-line arguments with subcommand support and type-safe validation. */
|
|
117
|
+
parseArgv(argv?: string[]): ParseArgvResult<Arguments, Options & O>;
|
|
118
|
+
/**
|
|
119
|
+
* Sets the main action handler for this command, which is executed after any matching option hooks when the command is invoked.
|
|
120
|
+
* The handler receives parsed arguments and options with correct typings.
|
|
121
|
+
*/
|
|
122
|
+
setAction(fn: ActionHandler<A, O, Subs>): this;
|
|
148
123
|
/** Returns a new Command instance. Override this method in subclasses. */
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
/** Base descriptor for command-line arguments with shared properties */
|
|
152
|
-
export interface ArgumentDescriptorBase {
|
|
153
|
-
name: string;
|
|
154
|
-
description: string;
|
|
155
|
-
required?: boolean;
|
|
156
|
-
variadic?: boolean;
|
|
157
|
-
choices?: string[];
|
|
158
|
-
defaultValue?: string | string[];
|
|
159
|
-
defaultValueDescription?: string;
|
|
160
|
-
}
|
|
161
|
-
/** Required positional argument descriptor. Usage: `<name>` */
|
|
162
|
-
interface RequiredArgumentDescriptor extends ArgumentDescriptorBase {
|
|
163
|
-
variadic?: false;
|
|
164
|
-
required: true;
|
|
165
|
-
defaultValue?: undefined;
|
|
166
|
-
defaultValueDescription?: undefined;
|
|
167
|
-
}
|
|
168
|
-
/** Optional positional argument with string default. Usage: `[name]` */
|
|
169
|
-
interface OptionalArgumentDescriptor extends ArgumentDescriptorBase {
|
|
170
|
-
required?: false;
|
|
171
|
-
variadic?: false;
|
|
172
|
-
defaultValue?: string;
|
|
173
|
-
defaultValueDescription?: string;
|
|
174
|
-
}
|
|
175
|
-
/** Required variadic argument accepting variadic values. Usage: `<name...>` */
|
|
176
|
-
interface RequiredVariadicArgumentDescriptor extends ArgumentDescriptorBase {
|
|
177
|
-
required: true;
|
|
178
|
-
variadic: true;
|
|
179
|
-
defaultValue?: undefined;
|
|
180
|
-
defaultValueDescription?: undefined;
|
|
181
|
-
}
|
|
182
|
-
/** Optional variadic argument with array default. Usage: `[name...]` */
|
|
183
|
-
interface OptionalVariadicArgumentDescriptor extends ArgumentDescriptorBase {
|
|
184
|
-
required?: false;
|
|
185
|
-
variadic: true;
|
|
186
|
-
defaultValue?: string[];
|
|
187
|
-
defaultValueDescription?: string;
|
|
188
|
-
}
|
|
189
|
-
/** Union type for all argument descriptor variants */
|
|
190
|
-
type ArgumentDescriptorStrict = RequiredArgumentDescriptor | OptionalArgumentDescriptor | RequiredVariadicArgumentDescriptor | OptionalVariadicArgumentDescriptor;
|
|
191
|
-
/** Helper type for extracting argument configuration options */
|
|
192
|
-
type ArgOpts<T extends ArgumentDescriptorStrict> = Omit<T, 'name' | 'description' | 'required' | 'variadic'>;
|
|
193
|
-
/** Base descriptor for command-line options with shared properties */
|
|
194
|
-
export interface OptionDescriptorBase extends Omit<ParseArgsOptionDescriptor, 'type'> {
|
|
195
|
-
type?: ParseArgsOptionDescriptor['type'];
|
|
196
|
-
flags: string;
|
|
197
|
-
short: string;
|
|
198
|
-
long: string;
|
|
199
|
-
name: string;
|
|
200
|
-
argName?: string;
|
|
201
|
-
description: string;
|
|
202
|
-
required?: boolean;
|
|
203
|
-
optional?: boolean;
|
|
204
|
-
variadic?: boolean;
|
|
205
|
-
negate?: boolean;
|
|
206
|
-
defaultValue?: boolean | string | string[];
|
|
207
|
-
defaultValueDescription?: string;
|
|
208
|
-
env?: string;
|
|
209
|
-
hidden?: boolean;
|
|
210
|
-
choices?: string[];
|
|
211
|
-
group?: string;
|
|
212
|
-
}
|
|
213
|
-
/** Boolean flag option. Usage: `-v, --verbose` */
|
|
214
|
-
interface BooleanOptionDescriptor extends OptionDescriptorBase {
|
|
215
|
-
type: 'boolean';
|
|
216
|
-
argName?: undefined;
|
|
217
|
-
required?: false;
|
|
218
|
-
optional: true;
|
|
219
|
-
variadic?: false;
|
|
220
|
-
negate: boolean;
|
|
221
|
-
defaultValue?: boolean;
|
|
222
|
-
defaultValueDescription?: string;
|
|
223
|
-
}
|
|
224
|
-
/** Required string option. Usage: `-f, --file <path>` */
|
|
225
|
-
interface RequiredOptionDescriptor extends OptionDescriptorBase {
|
|
226
|
-
type: 'string';
|
|
227
|
-
argName: string;
|
|
228
|
-
required: true;
|
|
229
|
-
optional?: false;
|
|
230
|
-
variadic?: false;
|
|
231
|
-
negate?: false;
|
|
232
|
-
defaultValue?: undefined;
|
|
233
|
-
defaultValueDescription?: undefined;
|
|
234
|
-
}
|
|
235
|
-
/** Optional string option with default. Usage: `-o, --output [path]` */
|
|
236
|
-
interface OptionalOptionDescriptor extends OptionDescriptorBase {
|
|
237
|
-
type: 'string';
|
|
238
|
-
argName: string;
|
|
239
|
-
required?: false;
|
|
240
|
-
optional: true;
|
|
241
|
-
variadic?: false;
|
|
242
|
-
negate?: false;
|
|
243
|
-
defaultValue?: string;
|
|
244
|
-
defaultValueDescription?: string;
|
|
245
|
-
}
|
|
246
|
-
/** Required option accepting variadic values. Usage: `-i, --include <patterns...>` */
|
|
247
|
-
interface RequiredVariadicOptionDescriptor extends OptionDescriptorBase {
|
|
248
|
-
type: 'string';
|
|
249
|
-
argName: string;
|
|
250
|
-
required: true;
|
|
251
|
-
optional?: false;
|
|
252
|
-
variadic: true;
|
|
253
|
-
negate?: false;
|
|
254
|
-
defaultValue?: undefined;
|
|
255
|
-
defaultValueDescription?: undefined;
|
|
256
|
-
}
|
|
257
|
-
/** Optional option accepting variadic values with defaults. Usage: `-e, --exclude [patterns...]` */
|
|
258
|
-
interface OptionalVariadicOptionDescriptor extends OptionDescriptorBase {
|
|
259
|
-
type: 'string';
|
|
260
|
-
argName: string;
|
|
261
|
-
required?: false;
|
|
262
|
-
optional: true;
|
|
263
|
-
variadic: true;
|
|
264
|
-
negate?: false;
|
|
265
|
-
defaultValue?: string[];
|
|
266
|
-
defaultValueDescription?: string;
|
|
267
|
-
}
|
|
268
|
-
/** Union type for all option descriptor variants */
|
|
269
|
-
type OptionDescriptorStrict = BooleanOptionDescriptor | RequiredOptionDescriptor | OptionalOptionDescriptor | RequiredVariadicOptionDescriptor | OptionalVariadicOptionDescriptor;
|
|
270
|
-
/** Helper type for extracting option configuration options */
|
|
271
|
-
type OptOpts<T extends OptionDescriptorStrict> = Omit<T, 'name' | 'description' | 'required' | 'variadic' | 'negate' | 'optional' | 'type' | 'argName' | 'short' | 'long' | 'flags'>;
|
|
272
|
-
/** Complete command configuration including all properties and substructures */
|
|
273
|
-
export interface CommandDescriptor {
|
|
274
|
-
name: string;
|
|
275
|
-
version?: string;
|
|
276
|
-
aliases: string[];
|
|
277
|
-
summary?: string;
|
|
278
|
-
description: string;
|
|
279
|
-
hidden?: boolean;
|
|
280
|
-
group?: string;
|
|
281
|
-
parent: CommandDescriptor | null;
|
|
282
|
-
commands: CommandDescriptor[];
|
|
283
|
-
arguments: ArgumentDescriptorBase[];
|
|
284
|
-
options: OptionDescriptorBase[];
|
|
285
|
-
helpConfiguration: Partial<IHelp>;
|
|
124
|
+
protected createSubcommand(name: string): Command<[], O, {}>;
|
|
286
125
|
}
|
|
287
|
-
export type OptionDescriptor = AllUnionFields<OptionDescriptorStrict>;
|
|
288
|
-
export type ArgumentDescriptor = AllUnionFields<ArgumentDescriptorStrict>;
|
|
289
|
-
export {};
|
|
290
|
-
//# sourceMappingURL=Command.d.ts.map
|
package/lib/Help.d.ts
CHANGED
|
@@ -1,95 +1,92 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IHelp, Argument, ICommand, Option } from './types';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* This is a fork of the Help class from the 'commander' npm package. The Help class method names as well as the
|
|
4
|
+
* expected interface of the Command instance to parse, are both similar, but different and not compatible without
|
|
5
|
+
* custom adaptations, @see ICommand
|
|
4
6
|
*/
|
|
5
7
|
export declare class Help implements IHelp {
|
|
8
|
+
protected readonly cmd: ICommand;
|
|
6
9
|
/** output helpWidth, long lines are wrapped to fit */
|
|
7
10
|
helpWidth: number;
|
|
8
11
|
minWidthToWrap: number;
|
|
9
|
-
sortSubcommands
|
|
10
|
-
sortOptions
|
|
11
|
-
|
|
12
|
+
sortSubcommands: boolean;
|
|
13
|
+
sortOptions: boolean;
|
|
14
|
+
usageDisplayOptionsAs: string;
|
|
15
|
+
usageDisplaySubcommandAs: string;
|
|
16
|
+
constructor(cmd: ICommand);
|
|
12
17
|
/**
|
|
13
18
|
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
14
19
|
*/
|
|
15
|
-
visibleCommands(
|
|
20
|
+
visibleCommands(): ICommand[];
|
|
16
21
|
/**
|
|
17
22
|
* Compare options for sort.
|
|
18
23
|
*/
|
|
19
|
-
compareOptions(a:
|
|
24
|
+
compareOptions(a: Option, b: Option): number;
|
|
20
25
|
/**
|
|
21
26
|
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
22
27
|
*/
|
|
23
|
-
visibleOptions(
|
|
24
|
-
/**
|
|
25
|
-
* Get an array of the visible global options. (Not including help.)
|
|
26
|
-
*/
|
|
27
|
-
visibleGlobalOptions(cmd: CommandDescriptor): OptionDescriptorBase[];
|
|
28
|
+
visibleOptions(): Option[];
|
|
28
29
|
/**
|
|
29
30
|
* Get an array of the arguments if any have a description.
|
|
30
31
|
*/
|
|
31
|
-
visibleArguments(
|
|
32
|
+
visibleArguments(): Argument[];
|
|
32
33
|
/**
|
|
33
34
|
* Get the command term to show in the list of subcommands.
|
|
34
35
|
*/
|
|
35
|
-
subcommandTerm(
|
|
36
|
+
subcommandTerm(sub: ICommand): string;
|
|
36
37
|
/**
|
|
37
38
|
* Get the option term to show in the list of options.
|
|
38
39
|
*/
|
|
39
|
-
optionTerm(option:
|
|
40
|
+
optionTerm(option: Option): string;
|
|
40
41
|
/**
|
|
41
42
|
* Get the argument term to show in the list of arguments.
|
|
42
43
|
*/
|
|
43
|
-
argumentTerm(argument:
|
|
44
|
+
argumentTerm(argument: Argument): string;
|
|
44
45
|
/**
|
|
45
|
-
* Get the longest
|
|
46
|
+
* Get the longest subcommand primary alias length.
|
|
46
47
|
*/
|
|
47
|
-
|
|
48
|
+
longestSubcommandAliasLength(): number;
|
|
48
49
|
/**
|
|
49
|
-
* Get the longest
|
|
50
|
+
* Get the longest subcommand term length.
|
|
50
51
|
*/
|
|
51
|
-
|
|
52
|
+
longestSubcommandTermLength(): number;
|
|
52
53
|
/**
|
|
53
|
-
* Get the longest
|
|
54
|
+
* Get the longest option term length.
|
|
54
55
|
*/
|
|
55
|
-
|
|
56
|
+
longestOptionTermLength(): number;
|
|
56
57
|
/**
|
|
57
58
|
* Get the longest argument term length.
|
|
58
59
|
*/
|
|
59
|
-
longestArgumentTermLength(
|
|
60
|
+
longestArgumentTermLength(): number;
|
|
60
61
|
/**
|
|
61
62
|
* Get the command usage to be displayed at the top of the built-in help.
|
|
62
63
|
*/
|
|
63
|
-
commandUsage(
|
|
64
|
+
commandUsage(): string;
|
|
64
65
|
/**
|
|
65
66
|
* Get the description for the command.
|
|
66
67
|
*/
|
|
67
|
-
commandDescription(
|
|
68
|
+
commandDescription(): string;
|
|
68
69
|
/**
|
|
69
70
|
* Get the subcommand summary to show in the list of subcommands.
|
|
70
71
|
* (Fallback to description for backwards compatibility.)
|
|
71
72
|
*/
|
|
72
|
-
subcommandDescription(
|
|
73
|
+
subcommandDescription(sub: ICommand): string;
|
|
73
74
|
/**
|
|
74
75
|
* Get the option description to show in the list of options.
|
|
75
76
|
*/
|
|
76
|
-
optionDescription(option:
|
|
77
|
+
optionDescription(option: Option): string;
|
|
77
78
|
/**
|
|
78
79
|
* Get the argument description to show in the list of arguments.
|
|
79
80
|
*/
|
|
80
|
-
argumentDescription(argument:
|
|
81
|
+
argumentDescription(argument: Argument): string;
|
|
81
82
|
/**
|
|
82
83
|
* Format a list of items, given a heading and an array of formatted items.
|
|
83
84
|
*/
|
|
84
|
-
formatItemList(heading: string, items: string[]
|
|
85
|
+
formatItemList(heading: string, items: string[]): string[];
|
|
85
86
|
/**
|
|
86
87
|
* Group items by their help group heading.
|
|
87
88
|
*/
|
|
88
|
-
groupItems<T extends
|
|
89
|
-
/**
|
|
90
|
-
* Generate the built-in help text.
|
|
91
|
-
*/
|
|
92
|
-
formatHelp(cmd: CommandDescriptor, helper: IHelp): string;
|
|
89
|
+
groupItems<T extends ICommand | Option>(unsortedItems: T[], visibleItems: T[], getGroup: (item: T) => string): Map<string, T[]>;
|
|
93
90
|
/**
|
|
94
91
|
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
95
92
|
*/
|
|
@@ -153,7 +150,7 @@ export declare class Help implements IHelp {
|
|
|
153
150
|
/**
|
|
154
151
|
* Calculate the pad width from the maximum term length.
|
|
155
152
|
*/
|
|
156
|
-
padWidth(
|
|
153
|
+
padWidth(): number;
|
|
157
154
|
/**
|
|
158
155
|
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
159
156
|
*/
|
|
@@ -165,57 +162,14 @@ export declare class Help implements IHelp {
|
|
|
165
162
|
* TTT DDD DDDD
|
|
166
163
|
* DD DDD
|
|
167
164
|
*/
|
|
168
|
-
formatItem(term: string, termWidth: number, description: string
|
|
165
|
+
formatItem(term: string, termWidth: number, description: string): string;
|
|
169
166
|
/**
|
|
170
167
|
* Wrap a string at whitespace, preserving existing line breaks.
|
|
171
168
|
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
172
169
|
*/
|
|
173
170
|
boxWrap(str: string, width: number): string;
|
|
171
|
+
/**
|
|
172
|
+
* Generate the built-in help text.
|
|
173
|
+
*/
|
|
174
|
+
render(): string;
|
|
174
175
|
}
|
|
175
|
-
export interface IHelp {
|
|
176
|
-
helpWidth: number;
|
|
177
|
-
minWidthToWrap: number;
|
|
178
|
-
sortSubcommands?: boolean;
|
|
179
|
-
sortOptions?: boolean;
|
|
180
|
-
showGlobalOptions?: boolean;
|
|
181
|
-
subcommandTerm(cmd: CommandDescriptor): string;
|
|
182
|
-
subcommandDescription(cmd: CommandDescriptor): string;
|
|
183
|
-
optionTerm(option: OptionDescriptorBase): string;
|
|
184
|
-
optionDescription(option: OptionDescriptorBase): string;
|
|
185
|
-
argumentTerm(argument: ArgumentDescriptorBase): string;
|
|
186
|
-
argumentDescription(argument: ArgumentDescriptorBase): string;
|
|
187
|
-
commandUsage(cmd: CommandDescriptor): string;
|
|
188
|
-
commandDescription(cmd: CommandDescriptor): string;
|
|
189
|
-
visibleCommands(cmd: CommandDescriptor): CommandDescriptor[];
|
|
190
|
-
visibleOptions(cmd: CommandDescriptor): OptionDescriptorBase[];
|
|
191
|
-
visibleGlobalOptions(cmd: CommandDescriptor): OptionDescriptorBase[];
|
|
192
|
-
visibleArguments(cmd: CommandDescriptor): ArgumentDescriptorBase[];
|
|
193
|
-
longestSubcommandTermLength(cmd: CommandDescriptor, helper: IHelp): number;
|
|
194
|
-
longestOptionTermLength(cmd: CommandDescriptor, helper: IHelp): number;
|
|
195
|
-
longestGlobalOptionTermLength(cmd: CommandDescriptor, helper: IHelp): number;
|
|
196
|
-
longestArgumentTermLength(cmd: CommandDescriptor, helper: IHelp): number;
|
|
197
|
-
displayWidth(str: string): number;
|
|
198
|
-
styleTitle(title: string): string;
|
|
199
|
-
styleUsage(str: string): string;
|
|
200
|
-
styleCommandText(str: string): string;
|
|
201
|
-
styleCommandDescription(str: string): string;
|
|
202
|
-
styleOptionDescription(str: string): string;
|
|
203
|
-
styleSubcommandDescription(str: string): string;
|
|
204
|
-
styleArgumentDescription(str: string): string;
|
|
205
|
-
styleDescriptionText(str: string): string;
|
|
206
|
-
styleOptionTerm(str: string): string;
|
|
207
|
-
styleSubcommandTerm(str: string): string;
|
|
208
|
-
styleArgumentTerm(str: string): string;
|
|
209
|
-
styleOptionText(str: string): string;
|
|
210
|
-
styleSubcommandText(str: string): string;
|
|
211
|
-
styleArgumentText(str: string): string;
|
|
212
|
-
compareOptions(a: OptionDescriptorBase, b: OptionDescriptorBase): number;
|
|
213
|
-
padWidth(cmd: CommandDescriptor, helper: IHelp): number;
|
|
214
|
-
boxWrap(str: string, width: number): string;
|
|
215
|
-
preformatted(str: string): boolean;
|
|
216
|
-
formatItem(term: string, termWidth: number, description: string, helper: IHelp): string;
|
|
217
|
-
formatItemList(heading: string, items: string[], helper: IHelp): string[];
|
|
218
|
-
groupItems<T extends CommandDescriptor | OptionDescriptorBase>(unsortedItems: T[], visibleItems: T[], getGroup: (item: T) => string): Map<string, T[]>;
|
|
219
|
-
formatHelp(cmd: CommandDescriptor, helper: IHelp): string;
|
|
220
|
-
}
|
|
221
|
-
//# sourceMappingURL=Help.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CamelCase } from 'type-fest';
|
|
2
|
+
import type { OptionUsage } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Parses option flags string into its components
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseOptionFlags<Long extends string>(flags: OptionUsage<Long>): {
|
|
7
|
+
short: string;
|
|
8
|
+
long: Long;
|
|
9
|
+
name: CamelCase<Long>;
|
|
10
|
+
argName: string | undefined;
|
|
11
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Option } from '../types';
|
|
2
|
+
/** Collect consecutive positional tokens into variadic string option values */
|
|
3
|
+
export declare function collectVariadicOptionValues(parsed: {
|
|
4
|
+
tokens: any[];
|
|
5
|
+
values: any;
|
|
6
|
+
positionals: string[];
|
|
7
|
+
}, options: Option[]): void;
|