@guanghechen/commander 4.5.1 → 4.6.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/CHANGELOG.md +7 -0
- package/README.md +81 -25
- package/lib/cjs/index.cjs +526 -148
- package/lib/esm/index.mjs +525 -146
- package/lib/types/index.d.ts +70 -24
- package/package.json +2 -1
package/lib/types/index.d.ts
CHANGED
|
@@ -93,6 +93,8 @@ interface ICommandArgumentConfig<T = unknown> {
|
|
|
93
93
|
coerce?: (rawValue: string) => T;
|
|
94
94
|
}
|
|
95
95
|
interface ICommandBuiltinOptionConfig {
|
|
96
|
+
/** Enable built-in --version option (root only, requires configured version) */
|
|
97
|
+
version?: boolean;
|
|
96
98
|
/** Enable built-in --color/--no-color option for help rendering (defaults respect NO_COLOR) */
|
|
97
99
|
color?: boolean;
|
|
98
100
|
/** Enable built-in --log-level option */
|
|
@@ -104,15 +106,9 @@ interface ICommandBuiltinOptionConfig {
|
|
|
104
106
|
/** Enable built-in --log-colorful/--no-log-colorful option */
|
|
105
107
|
logColorful?: boolean;
|
|
106
108
|
}
|
|
107
|
-
interface ICommandBuiltinCommandConfig {
|
|
108
|
-
/** Enable built-in help subcommand */
|
|
109
|
-
help?: boolean;
|
|
110
|
-
}
|
|
111
109
|
interface ICommandBuiltinConfig {
|
|
112
110
|
/** Built-in options configuration */
|
|
113
111
|
option?: boolean | ICommandBuiltinOptionConfig;
|
|
114
|
-
/** Built-in command configuration */
|
|
115
|
-
command?: boolean | ICommandBuiltinCommandConfig;
|
|
116
112
|
}
|
|
117
113
|
/** Command example configuration */
|
|
118
114
|
interface ICommandExample {
|
|
@@ -123,6 +119,15 @@ interface ICommandExample {
|
|
|
123
119
|
/** Example description */
|
|
124
120
|
desc: string;
|
|
125
121
|
}
|
|
122
|
+
/** Command preset defaults */
|
|
123
|
+
interface ICommandPresetConfig {
|
|
124
|
+
/** Preset root directory (absolute path) */
|
|
125
|
+
root?: string;
|
|
126
|
+
/** Default preset options file */
|
|
127
|
+
opt?: string;
|
|
128
|
+
/** Default preset envs file */
|
|
129
|
+
env?: string;
|
|
130
|
+
}
|
|
126
131
|
/** Command configuration */
|
|
127
132
|
interface ICommandConfig {
|
|
128
133
|
/** Command name (only for root command) */
|
|
@@ -133,6 +138,8 @@ interface ICommandConfig {
|
|
|
133
138
|
version?: string;
|
|
134
139
|
/** Built-in features configuration */
|
|
135
140
|
builtin?: boolean | ICommandBuiltinConfig;
|
|
141
|
+
/** Command-level preset defaults */
|
|
142
|
+
preset?: ICommandPresetConfig;
|
|
136
143
|
/** Default reporter for this command */
|
|
137
144
|
reporter?: IReporter;
|
|
138
145
|
}
|
|
@@ -141,6 +148,8 @@ interface ICommand {
|
|
|
141
148
|
readonly name: string | undefined;
|
|
142
149
|
readonly description: string;
|
|
143
150
|
readonly version: string | undefined;
|
|
151
|
+
readonly builtin: ICommandConfig['builtin'] | undefined;
|
|
152
|
+
readonly preset: ICommandPresetConfig | undefined;
|
|
144
153
|
readonly parent: ICommand | undefined;
|
|
145
154
|
readonly options: ICommandOptionConfig[];
|
|
146
155
|
readonly arguments: ICommandArgumentConfig[];
|
|
@@ -151,12 +160,16 @@ interface ICommand {
|
|
|
151
160
|
interface ICommandContext {
|
|
152
161
|
/** Current command node */
|
|
153
162
|
cmd: ICommand;
|
|
154
|
-
/**
|
|
163
|
+
/** Command chain from root to leaf */
|
|
164
|
+
chain: ICommand[];
|
|
165
|
+
/** Effective environment variables */
|
|
155
166
|
envs: Record<string, string | undefined>;
|
|
167
|
+
/** Built-in control hit status */
|
|
168
|
+
controls: ICommandControls;
|
|
169
|
+
/** Input source snapshots */
|
|
170
|
+
sources: ICommandInputSources;
|
|
156
171
|
/** Reporter instance */
|
|
157
172
|
reporter: IReporter;
|
|
158
|
-
/** Original argv */
|
|
159
|
-
argv: string[];
|
|
160
173
|
}
|
|
161
174
|
/** Action callback parameters */
|
|
162
175
|
interface ICommandActionParams {
|
|
@@ -185,11 +198,29 @@ type ICommandParsedOpts = Record<string, unknown>;
|
|
|
185
198
|
/** Parsed arguments record */
|
|
186
199
|
type ICommandParsedArgs = Record<string, unknown>;
|
|
187
200
|
/** Route stage result */
|
|
188
|
-
interface ICommandRouteResult {
|
|
201
|
+
interface ICommandRouteResult<TCommand = ICommand> {
|
|
189
202
|
/** Command chain from root to leaf */
|
|
190
|
-
chain:
|
|
203
|
+
chain: TCommand[];
|
|
191
204
|
/** Remaining argv after routing */
|
|
192
205
|
remaining: string[];
|
|
206
|
+
/** Routed command tokens from user argv (name/alias) */
|
|
207
|
+
cmds: string[];
|
|
208
|
+
}
|
|
209
|
+
/** Control-scan stage result */
|
|
210
|
+
interface ICommandControlScanResult {
|
|
211
|
+
/** Built-in control hit status */
|
|
212
|
+
controls: ICommandControls;
|
|
213
|
+
/** Remaining argv after stripping control tokens */
|
|
214
|
+
remaining: string[];
|
|
215
|
+
/** Optional target token from `help <child>` syntax */
|
|
216
|
+
helpTarget?: string;
|
|
217
|
+
}
|
|
218
|
+
/** Preset stage result */
|
|
219
|
+
interface ICommandPresetResult {
|
|
220
|
+
/** Effective tail argv after preset merge */
|
|
221
|
+
tailArgv: string[];
|
|
222
|
+
/** Effective envs after preset merge */
|
|
223
|
+
envs: Record<string, string | undefined>;
|
|
193
224
|
}
|
|
194
225
|
/** Tokenize stage result */
|
|
195
226
|
interface ICommandTokenizeResult {
|
|
@@ -223,8 +254,29 @@ interface ICommandParseResult {
|
|
|
223
254
|
/** Raw argument strings */
|
|
224
255
|
rawArgs: string[];
|
|
225
256
|
}
|
|
257
|
+
/** Input source snapshots for debugging/tracing */
|
|
258
|
+
interface ICommandInputSources {
|
|
259
|
+
preset: {
|
|
260
|
+
argv: string[];
|
|
261
|
+
envs: Record<string, string>;
|
|
262
|
+
};
|
|
263
|
+
user: {
|
|
264
|
+
/** Routed command tokens (name/alias as entered by user) */
|
|
265
|
+
cmds: string[];
|
|
266
|
+
/** Clean user tail argv after removing command chain/control/preset directives */
|
|
267
|
+
argv: string[];
|
|
268
|
+
/** Raw env snapshot from run/parse params */
|
|
269
|
+
envs: Record<string, string | undefined>;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
/** Built-in run controls */
|
|
273
|
+
interface ICommandControls {
|
|
274
|
+
help: boolean;
|
|
275
|
+
version: boolean;
|
|
276
|
+
}
|
|
226
277
|
/** Built-in option resolution result (internal) */
|
|
227
278
|
interface ICommandBuiltinOptionResolved {
|
|
279
|
+
version: boolean;
|
|
228
280
|
color: boolean;
|
|
229
281
|
logLevel: boolean;
|
|
230
282
|
silent: boolean;
|
|
@@ -234,9 +286,6 @@ interface ICommandBuiltinOptionResolved {
|
|
|
234
286
|
/** Built-in config resolution result (internal) */
|
|
235
287
|
interface ICommandBuiltinResolved {
|
|
236
288
|
option: ICommandBuiltinOptionResolved;
|
|
237
|
-
command: {
|
|
238
|
-
help: boolean;
|
|
239
|
-
};
|
|
240
289
|
}
|
|
241
290
|
/** Subcommand registry entry (internal) */
|
|
242
291
|
interface ISubcommandEntry<TCommand = ICommand> {
|
|
@@ -244,11 +293,6 @@ interface ISubcommandEntry<TCommand = ICommand> {
|
|
|
244
293
|
aliases: string[];
|
|
245
294
|
command: TCommand;
|
|
246
295
|
}
|
|
247
|
-
/** Internal route result */
|
|
248
|
-
interface IInternalRouteResult<TCommand = ICommand> {
|
|
249
|
-
chain: TCommand[];
|
|
250
|
-
remaining: string[];
|
|
251
|
-
}
|
|
252
296
|
/** Help option line (internal) */
|
|
253
297
|
interface IHelpOptionLine {
|
|
254
298
|
sig: string;
|
|
@@ -325,13 +369,13 @@ interface ICompletionCommandConfig {
|
|
|
325
369
|
/** Program name for completion scripts (defaults to root.name) */
|
|
326
370
|
programName?: string;
|
|
327
371
|
/** Default completion file paths for each shell */
|
|
328
|
-
paths
|
|
372
|
+
paths?: Partial<ICompletionPaths>;
|
|
329
373
|
}
|
|
330
374
|
|
|
331
375
|
/**
|
|
332
376
|
* Command class - CLI command builder with fluent API
|
|
333
377
|
*
|
|
334
|
-
* Execution flow: route → tokenize → resolve → parse → run
|
|
378
|
+
* Execution flow: route → control-scan → run-control(run) → preset → tokenize → resolve → parse → run
|
|
335
379
|
*
|
|
336
380
|
* @module @guanghechen/commander
|
|
337
381
|
*/
|
|
@@ -342,6 +386,8 @@ declare class Command implements ICommand {
|
|
|
342
386
|
get name(): string | undefined;
|
|
343
387
|
get description(): string;
|
|
344
388
|
get version(): string | undefined;
|
|
389
|
+
get builtin(): ICommandConfig['builtin'] | undefined;
|
|
390
|
+
get preset(): ICommandPresetConfig | undefined;
|
|
345
391
|
get parent(): Command | undefined;
|
|
346
392
|
get options(): ICommandOptionConfig[];
|
|
347
393
|
get arguments(): ICommandArgumentConfig[];
|
|
@@ -353,7 +399,7 @@ declare class Command implements ICommand {
|
|
|
353
399
|
example(title: string, usage: string, desc: string): this;
|
|
354
400
|
subcommand(name: string, cmd: Command): this;
|
|
355
401
|
run(params: ICommandRunParams): Promise<void>;
|
|
356
|
-
parse(params: ICommandRunParams): ICommandParseResult
|
|
402
|
+
parse(params: ICommandRunParams): Promise<ICommandParseResult>;
|
|
357
403
|
formatHelp(): string;
|
|
358
404
|
getCompletionMeta(): ICompletionMeta;
|
|
359
405
|
}
|
|
@@ -409,7 +455,7 @@ declare function isDomain(rawValue: string): boolean;
|
|
|
409
455
|
* ```
|
|
410
456
|
*/
|
|
411
457
|
declare class CompletionCommand extends Command {
|
|
412
|
-
constructor(root: Command, config
|
|
458
|
+
constructor(root: Command, config?: ICompletionCommandConfig);
|
|
413
459
|
}
|
|
414
460
|
declare class BashCompletion {
|
|
415
461
|
#private;
|
|
@@ -511,4 +557,4 @@ declare const logColorfulOption: ICommandOptionConfig<boolean>;
|
|
|
511
557
|
declare const silentOption: ICommandOptionConfig<boolean>;
|
|
512
558
|
|
|
513
559
|
export { BashCompletion, Coerce, Command, CommanderError, CompletionCommand, FishCompletion, PwshCompletion, isDomain, isIp, isIpv4, isIpv6, logColorfulOption, logDateOption, logLevelOption, silentOption };
|
|
514
|
-
export type { ICommand, ICommandAction, ICommandActionParams, ICommandArgumentConfig, ICommandArgumentKind, ICommandArgumentType,
|
|
560
|
+
export type { ICommand, ICommandAction, ICommandActionParams, ICommandArgumentConfig, ICommandArgumentKind, ICommandArgumentType, ICommandBuiltinConfig, ICommandBuiltinOptionConfig, ICommandBuiltinOptionResolved, ICommandBuiltinResolved, ICommandConfig, ICommandContext, ICommandControlScanResult, ICommandControls, ICommandExample, ICommandInputSources, ICommandOptionArgs, ICommandOptionConfig, ICommandOptionType, ICommandParseResult, ICommandParsedArgs, ICommandParsedOpts, ICommandPresetConfig, ICommandPresetResult, ICommandResolveResult, ICommandRouteResult, ICommandRunParams, ICommandShiftResult, ICommandToken, ICommandTokenType, ICommandTokenizeResult, ICommanderErrorKind, ICompletionCommandConfig, ICompletionMeta, ICompletionOptionMeta, ICompletionPaths, ICompletionShellType, IHelpCommandLine, IHelpData, IHelpExampleLine, IHelpOptionLine, ISubcommandEntry };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guanghechen/commander",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"description": "A minimal, type-safe command-line interface builder with fluent API",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "guanghechen",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"README.md"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
+
"@guanghechen/env": "^2.0.2",
|
|
44
45
|
"@guanghechen/reporter": "^3.3.0"
|
|
45
46
|
},
|
|
46
47
|
"scripts": {
|