@bemoje/cli 1.0.6 → 1.1.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/README.md +45 -157
- package/index.d.ts +0 -3
- package/index.js +0 -3
- package/lib/Command.d.ts +108 -111
- package/lib/Command.js +92 -106
- package/lib/Help.d.ts +41 -83
- package/lib/Help.js +14 -14
- package/package.json +4 -7
- package/lib/CommandHelpAdapter.d.ts +0 -157
- package/lib/CommandHelpAdapter.js +0 -102
- package/lib/CommanderHelpAdapter.d.ts +0 -56
- package/lib/CommanderHelpAdapter.js +0 -92
- package/lib/internal/lazyProp.d.ts +0 -5
- package/lib/internal/lazyProp.js +0 -24
- package/lib/renderHelp.d.ts +0 -6
- package/lib/renderHelp.js +0 -12
package/lib/Command.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ParseArgsOptionDescriptor } from 'node:util';
|
|
2
2
|
import type { IHelp } from './Help';
|
|
3
|
-
import {
|
|
3
|
+
import type { AllUnionFields } from 'type-fest';
|
|
4
4
|
/**
|
|
5
5
|
* Command-line argument parser with fluent API and type-safe validation.
|
|
6
6
|
* Enforces CLI argument ordering rules and provides structured parsing results.
|
|
@@ -8,12 +8,12 @@ import { CommandHelpAdapter } from './CommandHelpAdapter';
|
|
|
8
8
|
* @example
|
|
9
9
|
* ```typescript
|
|
10
10
|
* const cmd = new Command('myapp')
|
|
11
|
-
* .
|
|
12
|
-
* .
|
|
13
|
-
* .
|
|
14
|
-
* .
|
|
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
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* cmd.parseArgv(['input.txt', '-v', '-f', 'json'])
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
export declare class Command implements CommandDescriptor {
|
|
@@ -42,22 +42,6 @@ export declare class Command implements CommandDescriptor {
|
|
|
42
42
|
/** Help system configuration */
|
|
43
43
|
helpConfiguration: Partial<IHelp>;
|
|
44
44
|
constructor(name?: string, parent?: Command | null);
|
|
45
|
-
/** Updates multiple command properties at once */
|
|
46
|
-
setState(state: Partial<CommandDescriptor>): this;
|
|
47
|
-
/** Serializes command to JSON, maintaining compatibility with previous state-based structure */
|
|
48
|
-
toJSON(): {
|
|
49
|
-
name: string;
|
|
50
|
-
version: string;
|
|
51
|
-
aliases: string[];
|
|
52
|
-
summary: string;
|
|
53
|
-
description: string;
|
|
54
|
-
hidden: boolean;
|
|
55
|
-
group: string;
|
|
56
|
-
commands: Command[];
|
|
57
|
-
arguments: ArgumentDescriptor[];
|
|
58
|
-
options: OptionDescriptor[];
|
|
59
|
-
helpConfiguration: Partial<IHelp>;
|
|
60
|
-
};
|
|
61
45
|
/** Sets the command name */
|
|
62
46
|
setName(name: string): void;
|
|
63
47
|
/** Sets command aliases, flattening nested arrays */
|
|
@@ -68,7 +52,7 @@ export declare class Command implements CommandDescriptor {
|
|
|
68
52
|
setVersion(version?: string): this;
|
|
69
53
|
/** Sets the command summary */
|
|
70
54
|
setSummary(summary?: string): this;
|
|
71
|
-
/** Sets command description, joining
|
|
55
|
+
/** Sets command description, joining variadic lines */
|
|
72
56
|
setDescription(...lines: string[]): this;
|
|
73
57
|
/** Sets whether command is hidden from help */
|
|
74
58
|
setHidden(hidden?: boolean | undefined): this;
|
|
@@ -81,25 +65,26 @@ export declare class Command implements CommandDescriptor {
|
|
|
81
65
|
/** Sets help configuration, using defaults if not provided */
|
|
82
66
|
setHelpConfiguration(config?: Partial<IHelp>): this;
|
|
83
67
|
/** Creates and adds a subcommand */
|
|
84
|
-
|
|
68
|
+
addSubcommand(name: string): Command;
|
|
85
69
|
/** Add required argument. Usage: `<name>` */
|
|
86
|
-
|
|
70
|
+
addArgument(usage: `<${string}>`, description: string, options?: ArgOpts<RequiredArgumentDescriptor>): this;
|
|
87
71
|
/** Add optional argument with default. Usage: `[name]` */
|
|
88
|
-
|
|
72
|
+
addArgument(usage: `[${string}]`, description: string, options?: ArgOpts<OptionalArgumentDescriptor>): this;
|
|
89
73
|
/** Add required variadic argument. Usage: `<name...>` */
|
|
90
|
-
|
|
74
|
+
addArgument(usage: `<${string}...>`, description: string, options?: ArgOpts<RequiredVariadicArgumentDescriptor>): this;
|
|
91
75
|
/** Add optional variadic argument with defaults. Usage: `[name...]` */
|
|
92
|
-
|
|
76
|
+
addArgument(usage: `[${string}...]`, description: string, options?: ArgOpts<OptionalVariadicArgumentDescriptor>): this;
|
|
93
77
|
/** Add required string option. Usage: `-f, --file <path>` */
|
|
94
|
-
|
|
78
|
+
addOption(flags: `-${string}, --${string} <${string}>`, description: string, options?: OptOpts<RequiredOptionDescriptor>): this;
|
|
95
79
|
/** Add optional string option with default. Usage: `-o, --output [path]` */
|
|
96
|
-
|
|
80
|
+
addOption(flags: `-${string}, --${string} [${string}]`, description: string, options?: OptOpts<OptionalOptionDescriptor>): this;
|
|
97
81
|
/** Add required variadic option. Usage: `-i, --include <patterns...>` */
|
|
98
|
-
|
|
82
|
+
addOption(flags: `-${string}, --${string} <${string}...>`, description: string, options?: OptOpts<RequiredVariadicOptionDescriptor>): this;
|
|
99
83
|
/** Add optional variadic option with defaults. Usage: `-e, --exclude [patterns...]` */
|
|
100
|
-
|
|
84
|
+
addOption(flags: `-${string}, --${string} [${string}...]`, description: string, options?: OptOpts<OptionalVariadicOptionDescriptor>): this;
|
|
101
85
|
/** Add boolean flag option. Usage: `-v, --verbose` */
|
|
102
|
-
|
|
86
|
+
addOption(flags: `-${string}, --${string}`, description: string, options?: OptOpts<BooleanOptionDescriptor>): this;
|
|
87
|
+
private _addOption;
|
|
103
88
|
/**
|
|
104
89
|
* Parses command-line arguments with subcommand support and type-safe validation.
|
|
105
90
|
*
|
|
@@ -109,13 +94,15 @@ export declare class Command implements CommandDescriptor {
|
|
|
109
94
|
* // { arguments: ['input.txt'], options: { verbose: true, format: 'json' } }
|
|
110
95
|
* ```
|
|
111
96
|
*/
|
|
112
|
-
|
|
97
|
+
parseArgv(argv?: string[], globalOptions?: OptionDescriptor[]): {
|
|
113
98
|
command: Command;
|
|
114
99
|
arguments: (string | string[])[];
|
|
115
100
|
options: {
|
|
116
101
|
[x: string]: string | boolean | (string | boolean)[] | undefined;
|
|
117
102
|
};
|
|
118
103
|
};
|
|
104
|
+
/** Renders formatted help text using provided help definition */
|
|
105
|
+
renderHelp(help: IHelp): string;
|
|
119
106
|
/** Validates CLI argument ordering */
|
|
120
107
|
protected assertNoOptionalOrVariadicArguments(): void;
|
|
121
108
|
/** Validates optional args don't follow variadic args */
|
|
@@ -135,87 +122,89 @@ export declare class Command implements CommandDescriptor {
|
|
|
135
122
|
/** Returns all ancestor commands excluding this command */
|
|
136
123
|
getAncestors(): Command[];
|
|
137
124
|
/** Returns all options from this command and ancestors */
|
|
138
|
-
getOptionsInclAncestors():
|
|
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
|
+
}[];
|
|
139
144
|
/** Finds subcommand by name or alias */
|
|
140
145
|
findCommand(this: Command, name: string): Command;
|
|
141
146
|
/** Finds option by short or long name */
|
|
142
147
|
findOption(this: Command, arg: string): OptionDescriptor | undefined;
|
|
143
|
-
/** Returns a
|
|
144
|
-
|
|
145
|
-
/** Renders formatted help text using provided help definition */
|
|
146
|
-
renderHelp(help: IHelp): string;
|
|
148
|
+
/** Returns a new Command instance. Override this method in subclasses. */
|
|
149
|
+
createCommand(name?: string, parent?: Command | null): Command;
|
|
147
150
|
}
|
|
148
|
-
/** Usage patterns for boolean flag options */
|
|
149
|
-
type BooleanOptionUsage = `-${string}, --${string}`;
|
|
150
|
-
/** Usage patterns for required string options */
|
|
151
|
-
type RequiredOptionUsage = `-${string}, --${string} <${string}>`;
|
|
152
|
-
/** Usage patterns for optional string options */
|
|
153
|
-
type OptionalOptionUsage = `-${string}, --${string} [${string}]`;
|
|
154
|
-
/** Usage patterns for required variadic options */
|
|
155
|
-
type RequiredVariadicOptionUsage = `-${string}, --${string} <${string}...>`;
|
|
156
|
-
/** Usage patterns for optional variadic options */
|
|
157
|
-
type OptionalVariadicOptionUsage = `-${string}, --${string} [${string}...]`;
|
|
158
|
-
/** Union of all option usage pattern types */
|
|
159
|
-
export type OptionUsage = BooleanOptionUsage | RequiredOptionUsage | OptionalOptionUsage | RequiredVariadicOptionUsage | OptionalVariadicOptionUsage;
|
|
160
|
-
/** Usage pattern for required positional arguments */
|
|
161
|
-
type RequiredArgumentUsage = `<${string}>`;
|
|
162
|
-
/** Usage pattern for optional positional arguments */
|
|
163
|
-
type OptionalArgumentUsage = `[${string}]`;
|
|
164
|
-
/** Usage pattern for required variadic arguments */
|
|
165
|
-
type RequiredVariadicArgumentUsage = `<${string}...>`;
|
|
166
|
-
/** Usage pattern for optional variadic arguments */
|
|
167
|
-
type OptionalVariadicArgumentUsage = `[${string}...]`;
|
|
168
|
-
/** Union of all argument usage pattern types */
|
|
169
|
-
export type ArgumentUsage = RequiredArgumentUsage | OptionalArgumentUsage | RequiredVariadicArgumentUsage | OptionalVariadicArgumentUsage;
|
|
170
151
|
/** Base descriptor for command-line arguments with shared properties */
|
|
171
|
-
interface ArgumentDescriptorBase {
|
|
152
|
+
export interface ArgumentDescriptorBase {
|
|
172
153
|
name: string;
|
|
173
|
-
required: boolean;
|
|
174
154
|
description: string;
|
|
175
|
-
|
|
155
|
+
required?: boolean;
|
|
156
|
+
variadic?: boolean;
|
|
176
157
|
choices?: string[];
|
|
177
|
-
defaultValue?: string | string[]
|
|
178
|
-
defaultValueDescription?: string
|
|
158
|
+
defaultValue?: string | string[];
|
|
159
|
+
defaultValueDescription?: string;
|
|
179
160
|
}
|
|
180
161
|
/** Required positional argument descriptor. Usage: `<name>` */
|
|
181
162
|
interface RequiredArgumentDescriptor extends ArgumentDescriptorBase {
|
|
182
|
-
|
|
163
|
+
variadic?: false;
|
|
183
164
|
required: true;
|
|
184
|
-
defaultValue?:
|
|
185
|
-
defaultValueDescription?:
|
|
165
|
+
defaultValue?: undefined;
|
|
166
|
+
defaultValueDescription?: undefined;
|
|
186
167
|
}
|
|
187
168
|
/** Optional positional argument with string default. Usage: `[name]` */
|
|
188
169
|
interface OptionalArgumentDescriptor extends ArgumentDescriptorBase {
|
|
189
|
-
required
|
|
190
|
-
|
|
170
|
+
required?: false;
|
|
171
|
+
variadic?: false;
|
|
191
172
|
defaultValue?: string;
|
|
192
173
|
defaultValueDescription?: string;
|
|
193
174
|
}
|
|
194
|
-
/** Required variadic argument accepting
|
|
175
|
+
/** Required variadic argument accepting variadic values. Usage: `<name...>` */
|
|
195
176
|
interface RequiredVariadicArgumentDescriptor extends ArgumentDescriptorBase {
|
|
196
177
|
required: true;
|
|
197
|
-
|
|
198
|
-
defaultValue?:
|
|
199
|
-
defaultValueDescription?:
|
|
178
|
+
variadic: true;
|
|
179
|
+
defaultValue?: undefined;
|
|
180
|
+
defaultValueDescription?: undefined;
|
|
200
181
|
}
|
|
201
182
|
/** Optional variadic argument with array default. Usage: `[name...]` */
|
|
202
183
|
interface OptionalVariadicArgumentDescriptor extends ArgumentDescriptorBase {
|
|
203
|
-
required
|
|
204
|
-
|
|
184
|
+
required?: false;
|
|
185
|
+
variadic: true;
|
|
205
186
|
defaultValue?: string[];
|
|
206
187
|
defaultValueDescription?: string;
|
|
207
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'>;
|
|
208
193
|
/** Base descriptor for command-line options with shared properties */
|
|
209
|
-
interface OptionDescriptorBase extends ParseArgsOptionDescriptor {
|
|
210
|
-
type
|
|
194
|
+
export interface OptionDescriptorBase extends Omit<ParseArgsOptionDescriptor, 'type'> {
|
|
195
|
+
type?: ParseArgsOptionDescriptor['type'];
|
|
196
|
+
flags: string;
|
|
211
197
|
short: string;
|
|
198
|
+
long: string;
|
|
212
199
|
name: string;
|
|
213
|
-
argName?: string
|
|
200
|
+
argName?: string;
|
|
214
201
|
description: string;
|
|
215
|
-
required
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
202
|
+
required?: boolean;
|
|
203
|
+
optional?: boolean;
|
|
204
|
+
variadic?: boolean;
|
|
205
|
+
negate?: boolean;
|
|
206
|
+
defaultValue?: boolean | string | string[];
|
|
207
|
+
defaultValueDescription?: string;
|
|
219
208
|
env?: string;
|
|
220
209
|
hidden?: boolean;
|
|
221
210
|
choices?: string[];
|
|
@@ -224,9 +213,11 @@ interface OptionDescriptorBase extends ParseArgsOptionDescriptor {
|
|
|
224
213
|
/** Boolean flag option. Usage: `-v, --verbose` */
|
|
225
214
|
interface BooleanOptionDescriptor extends OptionDescriptorBase {
|
|
226
215
|
type: 'boolean';
|
|
227
|
-
argName?:
|
|
228
|
-
required
|
|
229
|
-
|
|
216
|
+
argName?: undefined;
|
|
217
|
+
required?: false;
|
|
218
|
+
optional: true;
|
|
219
|
+
variadic?: false;
|
|
220
|
+
negate: boolean;
|
|
230
221
|
defaultValue?: boolean;
|
|
231
222
|
defaultValueDescription?: string;
|
|
232
223
|
}
|
|
@@ -235,37 +226,49 @@ interface RequiredOptionDescriptor extends OptionDescriptorBase {
|
|
|
235
226
|
type: 'string';
|
|
236
227
|
argName: string;
|
|
237
228
|
required: true;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
229
|
+
optional?: false;
|
|
230
|
+
variadic?: false;
|
|
231
|
+
negate?: false;
|
|
232
|
+
defaultValue?: undefined;
|
|
233
|
+
defaultValueDescription?: undefined;
|
|
241
234
|
}
|
|
242
235
|
/** Optional string option with default. Usage: `-o, --output [path]` */
|
|
243
236
|
interface OptionalOptionDescriptor extends OptionDescriptorBase {
|
|
244
237
|
type: 'string';
|
|
245
238
|
argName: string;
|
|
246
|
-
required
|
|
247
|
-
|
|
239
|
+
required?: false;
|
|
240
|
+
optional: true;
|
|
241
|
+
variadic?: false;
|
|
242
|
+
negate?: false;
|
|
248
243
|
defaultValue?: string;
|
|
249
244
|
defaultValueDescription?: string;
|
|
250
245
|
}
|
|
251
|
-
/** Required option accepting
|
|
246
|
+
/** Required option accepting variadic values. Usage: `-i, --include <patterns...>` */
|
|
252
247
|
interface RequiredVariadicOptionDescriptor extends OptionDescriptorBase {
|
|
253
248
|
type: 'string';
|
|
254
249
|
argName: string;
|
|
255
250
|
required: true;
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
251
|
+
optional?: false;
|
|
252
|
+
variadic: true;
|
|
253
|
+
negate?: false;
|
|
254
|
+
defaultValue?: undefined;
|
|
255
|
+
defaultValueDescription?: undefined;
|
|
259
256
|
}
|
|
260
|
-
/** Optional option accepting
|
|
257
|
+
/** Optional option accepting variadic values with defaults. Usage: `-e, --exclude [patterns...]` */
|
|
261
258
|
interface OptionalVariadicOptionDescriptor extends OptionDescriptorBase {
|
|
262
259
|
type: 'string';
|
|
263
260
|
argName: string;
|
|
264
|
-
required
|
|
265
|
-
|
|
261
|
+
required?: false;
|
|
262
|
+
optional: true;
|
|
263
|
+
variadic: true;
|
|
264
|
+
negate?: false;
|
|
266
265
|
defaultValue?: string[];
|
|
267
266
|
defaultValueDescription?: string;
|
|
268
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'>;
|
|
269
272
|
/** Complete command configuration including all properties and substructures */
|
|
270
273
|
export interface CommandDescriptor {
|
|
271
274
|
name: string;
|
|
@@ -275,19 +278,13 @@ export interface CommandDescriptor {
|
|
|
275
278
|
description: string;
|
|
276
279
|
hidden?: boolean;
|
|
277
280
|
group?: string;
|
|
278
|
-
parent:
|
|
279
|
-
commands:
|
|
280
|
-
arguments:
|
|
281
|
-
options:
|
|
281
|
+
parent: CommandDescriptor | null;
|
|
282
|
+
commands: CommandDescriptor[];
|
|
283
|
+
arguments: ArgumentDescriptorBase[];
|
|
284
|
+
options: OptionDescriptorBase[];
|
|
282
285
|
helpConfiguration: Partial<IHelp>;
|
|
283
286
|
}
|
|
284
|
-
|
|
285
|
-
export type ArgumentDescriptor =
|
|
286
|
-
/** Union type for all option descriptor variants */
|
|
287
|
-
export type OptionDescriptor = BooleanOptionDescriptor | RequiredOptionDescriptor | OptionalOptionDescriptor | RequiredVariadicOptionDescriptor | OptionalVariadicOptionDescriptor;
|
|
288
|
-
/** Helper type for extracting argument configuration options */
|
|
289
|
-
type ArgOpts<T extends ArgumentDescriptor> = Omit<T, 'name' | 'description' | 'required' | 'multiple'>;
|
|
290
|
-
/** Helper type for extracting option configuration options */
|
|
291
|
-
type OptOpts<T extends OptionDescriptor> = Omit<T, 'name' | 'description' | 'required' | 'multiple' | 'type' | 'argName' | 'short' | 'long'>;
|
|
287
|
+
export type OptionDescriptor = AllUnionFields<OptionDescriptorStrict>;
|
|
288
|
+
export type ArgumentDescriptor = AllUnionFields<ArgumentDescriptorStrict>;
|
|
292
289
|
export {};
|
|
293
290
|
//# sourceMappingURL=Command.d.ts.map
|