@guanghechen/commander 4.7.1 → 4.7.2
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/lib/cjs/browser.cjs +289 -41
- package/lib/cjs/index.cjs +1028 -176
- package/lib/cjs/node.cjs +597 -53
- package/lib/esm/browser.mjs +289 -41
- package/lib/esm/index.mjs +1021 -175
- package/lib/esm/node.mjs +597 -53
- package/lib/types/browser.d.ts +26 -5
- package/lib/types/index.d.ts +191 -15
- package/lib/types/node.d.ts +26 -5
- package/package.json +1 -1
package/lib/types/browser.d.ts
CHANGED
|
@@ -65,9 +65,9 @@ interface ICommandOptionConfig<T = unknown> {
|
|
|
65
65
|
apply?: (value: T, ctx: ICommandContext) => void;
|
|
66
66
|
}
|
|
67
67
|
/** Argument kind */
|
|
68
|
-
type ICommandArgumentKind = 'required' | 'optional' | 'variadic';
|
|
68
|
+
type ICommandArgumentKind = 'required' | 'optional' | 'variadic' | 'some';
|
|
69
69
|
/** Argument value type */
|
|
70
|
-
type ICommandArgumentType = 'string' | '
|
|
70
|
+
type ICommandArgumentType = 'string' | 'choice';
|
|
71
71
|
/**
|
|
72
72
|
* Positional argument configuration.
|
|
73
73
|
*
|
|
@@ -85,8 +85,10 @@ interface ICommandArgumentConfig<T = unknown> {
|
|
|
85
85
|
desc: string;
|
|
86
86
|
/** Argument kind: required / optional / variadic */
|
|
87
87
|
kind: ICommandArgumentKind;
|
|
88
|
-
/** Value type
|
|
89
|
-
type
|
|
88
|
+
/** Value type */
|
|
89
|
+
type: ICommandArgumentType;
|
|
90
|
+
/** Allowed values for choice type */
|
|
91
|
+
choices?: ReadonlyArray<string>;
|
|
90
92
|
/** Default value when not provided (only for optional arguments) */
|
|
91
93
|
default?: T;
|
|
92
94
|
/** Custom value transformation (takes precedence over type conversion) */
|
|
@@ -317,6 +319,11 @@ interface IHelpOptionLine {
|
|
|
317
319
|
sig: string;
|
|
318
320
|
desc: string;
|
|
319
321
|
}
|
|
322
|
+
/** Help argument line (internal) */
|
|
323
|
+
interface IHelpArgumentLine {
|
|
324
|
+
sig: string;
|
|
325
|
+
desc: string;
|
|
326
|
+
}
|
|
320
327
|
/** Help command line (internal) */
|
|
321
328
|
interface IHelpCommandLine {
|
|
322
329
|
name: string;
|
|
@@ -332,6 +339,7 @@ interface IHelpExampleLine {
|
|
|
332
339
|
interface IHelpData {
|
|
333
340
|
desc: string;
|
|
334
341
|
usage: string;
|
|
342
|
+
arguments: IHelpArgumentLine[];
|
|
335
343
|
options: IHelpOptionLine[];
|
|
336
344
|
commands: IHelpCommandLine[];
|
|
337
345
|
examples: IHelpExampleLine[];
|
|
@@ -361,6 +369,17 @@ interface ICompletionOptionMeta {
|
|
|
361
369
|
/** Allowed values */
|
|
362
370
|
choices?: string[];
|
|
363
371
|
}
|
|
372
|
+
/** Argument metadata for completion */
|
|
373
|
+
interface ICompletionArgumentMeta {
|
|
374
|
+
/** Argument name */
|
|
375
|
+
name: string;
|
|
376
|
+
/** Argument kind */
|
|
377
|
+
kind: ICommandArgumentKind;
|
|
378
|
+
/** Argument type */
|
|
379
|
+
type: ICommandArgumentType;
|
|
380
|
+
/** Allowed values (only for type='choice') */
|
|
381
|
+
choices?: string[];
|
|
382
|
+
}
|
|
364
383
|
/** Command metadata for completion */
|
|
365
384
|
interface ICompletionMeta {
|
|
366
385
|
/** Command name */
|
|
@@ -371,6 +390,8 @@ interface ICompletionMeta {
|
|
|
371
390
|
aliases: string[];
|
|
372
391
|
/** Options */
|
|
373
392
|
options: ICompletionOptionMeta[];
|
|
393
|
+
/** Positional arguments */
|
|
394
|
+
arguments: ICompletionArgumentMeta[];
|
|
374
395
|
/** Subcommands */
|
|
375
396
|
subcommands: ICompletionMeta[];
|
|
376
397
|
}
|
|
@@ -548,4 +569,4 @@ declare function getDefaultCommandRuntime(): ICommandRuntime;
|
|
|
548
569
|
declare function setDefaultCommandRuntime(runtime: ICommandRuntime): void;
|
|
549
570
|
|
|
550
571
|
export { Coerce, Command, CommanderError, createBrowserCommandRuntime, getDefaultCommandRuntime, isDomain, isIp, isIpv4, isIpv6, logColorfulOption, logDateOption, logLevelOption, setDefaultCommandRuntime, silentOption };
|
|
551
|
-
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, ICommandRuntime, ICommandRuntimeStats, ICommandShiftResult, ICommandToken, ICommandTokenType, ICommandTokenizeResult, ICommanderErrorKind, ICompletionCommandConfig, ICompletionMeta, ICompletionOptionMeta, ICompletionPaths, ICompletionShellType, IHelpCommandLine, IHelpData, IHelpExampleLine, IHelpOptionLine, ISubcommandEntry };
|
|
572
|
+
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, ICommandRuntime, ICommandRuntimeStats, ICommandShiftResult, ICommandToken, ICommandTokenType, ICommandTokenizeResult, ICommanderErrorKind, ICompletionArgumentMeta, ICompletionCommandConfig, ICompletionMeta, ICompletionOptionMeta, ICompletionPaths, ICompletionShellType, IHelpArgumentLine, IHelpCommandLine, IHelpData, IHelpExampleLine, IHelpOptionLine, ISubcommandEntry };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -92,16 +92,54 @@ interface ICommandArgumentConfig<T = unknown> {
|
|
|
92
92
|
/** Custom value transformation (takes precedence over type conversion) */
|
|
93
93
|
coerce?: (rawValue: string) => T;
|
|
94
94
|
}
|
|
95
|
+
interface ICommandBuiltinOptionConfig {
|
|
96
|
+
/** Enable built-in --version option (root only, requires configured version) */
|
|
97
|
+
version?: boolean;
|
|
98
|
+
/** Enable built-in --color/--no-color option for help rendering (defaults respect NO_COLOR) */
|
|
99
|
+
color?: boolean;
|
|
100
|
+
/** Enable built-in --log-level option */
|
|
101
|
+
logLevel?: boolean;
|
|
102
|
+
/** Enable built-in --silent option */
|
|
103
|
+
silent?: boolean;
|
|
104
|
+
/** Enable built-in --log-date/--no-log-date option */
|
|
105
|
+
logDate?: boolean;
|
|
106
|
+
/** Enable built-in --log-colorful/--no-log-colorful option */
|
|
107
|
+
logColorful?: boolean;
|
|
108
|
+
}
|
|
109
|
+
interface ICommandBuiltinConfig {
|
|
110
|
+
/** Built-in options configuration */
|
|
111
|
+
option?: boolean | ICommandBuiltinOptionConfig;
|
|
112
|
+
}
|
|
113
|
+
/** Command example configuration */
|
|
114
|
+
interface ICommandExample {
|
|
115
|
+
/** Example title */
|
|
116
|
+
title: string;
|
|
117
|
+
/** Usage fragment relative to command path */
|
|
118
|
+
usage: string;
|
|
119
|
+
/** Example description */
|
|
120
|
+
desc: string;
|
|
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
|
+
}
|
|
95
131
|
/** Command configuration */
|
|
96
132
|
interface ICommandConfig {
|
|
97
133
|
/** Command name (only for root command) */
|
|
98
134
|
name?: string;
|
|
99
135
|
/** Command description */
|
|
100
136
|
desc: string;
|
|
101
|
-
/** Version (for
|
|
137
|
+
/** Version (for built-in --version on this command) */
|
|
102
138
|
version?: string;
|
|
103
|
-
/**
|
|
104
|
-
|
|
139
|
+
/** Built-in features configuration */
|
|
140
|
+
builtin?: boolean | ICommandBuiltinConfig;
|
|
141
|
+
/** Command-level preset defaults */
|
|
142
|
+
preset?: ICommandPresetConfig;
|
|
105
143
|
/** Default reporter for this command */
|
|
106
144
|
reporter?: IReporter;
|
|
107
145
|
}
|
|
@@ -110,21 +148,28 @@ interface ICommand {
|
|
|
110
148
|
readonly name: string | undefined;
|
|
111
149
|
readonly description: string;
|
|
112
150
|
readonly version: string | undefined;
|
|
151
|
+
readonly builtin: ICommandConfig['builtin'] | undefined;
|
|
152
|
+
readonly preset: ICommandPresetConfig | undefined;
|
|
113
153
|
readonly parent: ICommand | undefined;
|
|
114
154
|
readonly options: ICommandOptionConfig[];
|
|
115
155
|
readonly arguments: ICommandArgumentConfig[];
|
|
156
|
+
readonly examples: ICommandExample[];
|
|
116
157
|
readonly subcommands: Map<string, ICommand>;
|
|
117
158
|
}
|
|
118
159
|
/** Execution context */
|
|
119
160
|
interface ICommandContext {
|
|
120
161
|
/** Current command node */
|
|
121
162
|
cmd: ICommand;
|
|
122
|
-
/**
|
|
163
|
+
/** Command chain from root to leaf */
|
|
164
|
+
chain: ICommand[];
|
|
165
|
+
/** Effective environment variables */
|
|
123
166
|
envs: Record<string, string | undefined>;
|
|
167
|
+
/** Built-in control hit status */
|
|
168
|
+
controls: ICommandControls;
|
|
169
|
+
/** Input source snapshots */
|
|
170
|
+
sources: ICommandInputSources;
|
|
124
171
|
/** Reporter instance */
|
|
125
172
|
reporter: IReporter;
|
|
126
|
-
/** Original argv */
|
|
127
|
-
argv: string[];
|
|
128
173
|
}
|
|
129
174
|
/** Action callback parameters */
|
|
130
175
|
interface ICommandActionParams {
|
|
@@ -153,11 +198,29 @@ type ICommandParsedOpts = Record<string, unknown>;
|
|
|
153
198
|
/** Parsed arguments record */
|
|
154
199
|
type ICommandParsedArgs = Record<string, unknown>;
|
|
155
200
|
/** Route stage result */
|
|
156
|
-
interface ICommandRouteResult {
|
|
201
|
+
interface ICommandRouteResult<TCommand = ICommand> {
|
|
157
202
|
/** Command chain from root to leaf */
|
|
158
|
-
chain:
|
|
203
|
+
chain: TCommand[];
|
|
159
204
|
/** Remaining argv after routing */
|
|
160
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>;
|
|
161
224
|
}
|
|
162
225
|
/** Tokenize stage result */
|
|
163
226
|
interface ICommandTokenizeResult {
|
|
@@ -191,8 +254,71 @@ interface ICommandParseResult {
|
|
|
191
254
|
/** Raw argument strings */
|
|
192
255
|
rawArgs: string[];
|
|
193
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
|
+
}
|
|
277
|
+
/** Built-in option resolution result (internal) */
|
|
278
|
+
interface ICommandBuiltinOptionResolved {
|
|
279
|
+
version: boolean;
|
|
280
|
+
color: boolean;
|
|
281
|
+
logLevel: boolean;
|
|
282
|
+
silent: boolean;
|
|
283
|
+
logDate: boolean;
|
|
284
|
+
logColorful: boolean;
|
|
285
|
+
}
|
|
286
|
+
/** Built-in config resolution result (internal) */
|
|
287
|
+
interface ICommandBuiltinResolved {
|
|
288
|
+
option: ICommandBuiltinOptionResolved;
|
|
289
|
+
}
|
|
290
|
+
/** Subcommand registry entry (internal) */
|
|
291
|
+
interface ISubcommandEntry<TCommand = ICommand> {
|
|
292
|
+
name: string;
|
|
293
|
+
aliases: string[];
|
|
294
|
+
command: TCommand;
|
|
295
|
+
}
|
|
296
|
+
/** Help option line (internal) */
|
|
297
|
+
interface IHelpOptionLine {
|
|
298
|
+
sig: string;
|
|
299
|
+
desc: string;
|
|
300
|
+
}
|
|
301
|
+
/** Help command line (internal) */
|
|
302
|
+
interface IHelpCommandLine {
|
|
303
|
+
name: string;
|
|
304
|
+
desc: string;
|
|
305
|
+
}
|
|
306
|
+
/** Help example line (internal) */
|
|
307
|
+
interface IHelpExampleLine {
|
|
308
|
+
title: string;
|
|
309
|
+
usage: string;
|
|
310
|
+
desc: string;
|
|
311
|
+
}
|
|
312
|
+
/** Structured help data for rendering (internal) */
|
|
313
|
+
interface IHelpData {
|
|
314
|
+
desc: string;
|
|
315
|
+
usage: string;
|
|
316
|
+
options: IHelpOptionLine[];
|
|
317
|
+
commands: IHelpCommandLine[];
|
|
318
|
+
examples: IHelpExampleLine[];
|
|
319
|
+
}
|
|
194
320
|
/** Error kinds for command parsing */
|
|
195
|
-
type ICommanderErrorKind = 'InvalidOptionFormat' | 'InvalidNegativeOption' | 'NegativeOptionWithValue' | 'NegativeOptionType' | 'UnknownOption' | 'UnexpectedArgument' | 'MissingValue' | 'InvalidType' | 'UnsupportedShortSyntax' | 'OptionConflict' | 'MissingRequired' | 'InvalidChoice' | 'InvalidBooleanValue' | 'MissingRequiredArgument' | 'TooManyArguments' | 'ConfigurationError';
|
|
321
|
+
type ICommanderErrorKind = 'InvalidOptionFormat' | 'InvalidNegativeOption' | 'NegativeOptionWithValue' | 'NegativeOptionType' | 'UnknownOption' | 'UnknownSubcommand' | 'UnexpectedArgument' | 'MissingValue' | 'InvalidType' | 'UnsupportedShortSyntax' | 'OptionConflict' | 'MissingRequired' | 'InvalidChoice' | 'InvalidBooleanValue' | 'MissingRequiredArgument' | 'TooManyArguments' | 'ConfigurationError';
|
|
196
322
|
/** Commander error with structured information */
|
|
197
323
|
declare class CommanderError extends Error {
|
|
198
324
|
readonly kind: ICommanderErrorKind;
|
|
@@ -243,13 +369,13 @@ interface ICompletionCommandConfig {
|
|
|
243
369
|
/** Program name for completion scripts (defaults to root.name) */
|
|
244
370
|
programName?: string;
|
|
245
371
|
/** Default completion file paths for each shell */
|
|
246
|
-
paths
|
|
372
|
+
paths?: Partial<ICompletionPaths>;
|
|
247
373
|
}
|
|
248
374
|
|
|
249
375
|
/**
|
|
250
376
|
* Command class - CLI command builder with fluent API
|
|
251
377
|
*
|
|
252
|
-
* Execution flow: route → tokenize → resolve → parse → run
|
|
378
|
+
* Execution flow: route → control-scan → run-control(run) → preset → tokenize → resolve → parse → run
|
|
253
379
|
*
|
|
254
380
|
* @module @guanghechen/commander
|
|
255
381
|
*/
|
|
@@ -260,20 +386,48 @@ declare class Command implements ICommand {
|
|
|
260
386
|
get name(): string | undefined;
|
|
261
387
|
get description(): string;
|
|
262
388
|
get version(): string | undefined;
|
|
389
|
+
get builtin(): ICommandConfig['builtin'] | undefined;
|
|
390
|
+
get preset(): ICommandPresetConfig | undefined;
|
|
263
391
|
get parent(): Command | undefined;
|
|
264
392
|
get options(): ICommandOptionConfig[];
|
|
265
393
|
get arguments(): ICommandArgumentConfig[];
|
|
394
|
+
get examples(): ICommandExample[];
|
|
266
395
|
get subcommands(): Map<string, ICommand>;
|
|
267
396
|
option<T>(opt: ICommandOptionConfig<T>): this;
|
|
268
397
|
argument<T>(arg: ICommandArgumentConfig<T>): this;
|
|
269
398
|
action(fn: ICommandAction): this;
|
|
399
|
+
example(title: string, usage: string, desc: string): this;
|
|
270
400
|
subcommand(name: string, cmd: Command): this;
|
|
271
401
|
run(params: ICommandRunParams): Promise<void>;
|
|
272
|
-
parse(params: ICommandRunParams): ICommandParseResult
|
|
402
|
+
parse(params: ICommandRunParams): Promise<ICommandParseResult>;
|
|
273
403
|
formatHelp(): string;
|
|
274
404
|
getCompletionMeta(): ICompletionMeta;
|
|
275
405
|
}
|
|
276
406
|
|
|
407
|
+
/**
|
|
408
|
+
* Pre-defined coerce factory methods for @guanghechen/commander.
|
|
409
|
+
*
|
|
410
|
+
* @module @guanghechen/commander/coerce
|
|
411
|
+
*/
|
|
412
|
+
declare class Coerce {
|
|
413
|
+
private constructor();
|
|
414
|
+
private static create;
|
|
415
|
+
static choice<TValue extends string>(name: string, values: ReadonlyArray<TValue>, errorMessage?: string): (rawValue: string) => TValue;
|
|
416
|
+
static domain(name: string, errorMessage?: string): (rawValue: string) => string;
|
|
417
|
+
static host(name: string, errorMessage?: string): (rawValue: string) => string;
|
|
418
|
+
static integer(name: string, errorMessage?: string): (rawValue: string) => number;
|
|
419
|
+
static ip(name: string, errorMessage?: string): (rawValue: string) => string;
|
|
420
|
+
static number(name: string, errorMessage?: string): (rawValue: string) => number;
|
|
421
|
+
static port(name: string, errorMessage?: string): (rawValue: string) => number;
|
|
422
|
+
static positiveInteger(name: string, errorMessage?: string): (rawValue: string) => number;
|
|
423
|
+
static positiveNumber(name: string, errorMessage?: string): (rawValue: string) => number;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
declare function isIpv4(rawValue: string): boolean;
|
|
427
|
+
declare function isIpv6(rawValue: string): boolean;
|
|
428
|
+
declare function isIp(rawValue: string): boolean;
|
|
429
|
+
declare function isDomain(rawValue: string): boolean;
|
|
430
|
+
|
|
277
431
|
/**
|
|
278
432
|
* Shell completion generators
|
|
279
433
|
*
|
|
@@ -301,7 +455,7 @@ declare class Command implements ICommand {
|
|
|
301
455
|
* ```
|
|
302
456
|
*/
|
|
303
457
|
declare class CompletionCommand extends Command {
|
|
304
|
-
constructor(root: Command, config
|
|
458
|
+
constructor(root: Command, config?: ICompletionCommandConfig);
|
|
305
459
|
}
|
|
306
460
|
declare class BashCompletion {
|
|
307
461
|
#private;
|
|
@@ -355,6 +509,28 @@ declare class PwshCompletion {
|
|
|
355
509
|
* ```
|
|
356
510
|
*/
|
|
357
511
|
declare const logLevelOption: ICommandOptionConfig<string>;
|
|
512
|
+
/**
|
|
513
|
+
* Pre-defined --log-date option for controlling timestamp output.
|
|
514
|
+
*
|
|
515
|
+
* | Property | Value |
|
|
516
|
+
* | --------- | --------- |
|
|
517
|
+
* | long | 'logDate' |
|
|
518
|
+
* | type | 'boolean' |
|
|
519
|
+
* | args | 'none' |
|
|
520
|
+
* | default | true |
|
|
521
|
+
*/
|
|
522
|
+
declare const logDateOption: ICommandOptionConfig<boolean>;
|
|
523
|
+
/**
|
|
524
|
+
* Pre-defined --log-colorful option for controlling colorful output.
|
|
525
|
+
*
|
|
526
|
+
* | Property | Value |
|
|
527
|
+
* | --------- | ------------- |
|
|
528
|
+
* | long | 'logColorful' |
|
|
529
|
+
* | type | 'boolean' |
|
|
530
|
+
* | args | 'none' |
|
|
531
|
+
* | default | true |
|
|
532
|
+
*/
|
|
533
|
+
declare const logColorfulOption: ICommandOptionConfig<boolean>;
|
|
358
534
|
/**
|
|
359
535
|
* Pre-defined --silent option for suppressing non-error output.
|
|
360
536
|
*
|
|
@@ -380,5 +556,5 @@ declare const logLevelOption: ICommandOptionConfig<string>;
|
|
|
380
556
|
*/
|
|
381
557
|
declare const silentOption: ICommandOptionConfig<boolean>;
|
|
382
558
|
|
|
383
|
-
export { BashCompletion, Command, CommanderError, CompletionCommand, FishCompletion, PwshCompletion, logLevelOption, silentOption };
|
|
384
|
-
export type { ICommand, ICommandAction, ICommandActionParams, ICommandArgumentConfig, ICommandArgumentKind, ICommandArgumentType, ICommandConfig, ICommandContext, ICommandOptionArgs, ICommandOptionConfig, ICommandOptionType, ICommandParseResult, ICommandParsedArgs, ICommandParsedOpts, ICommandResolveResult, ICommandRouteResult, ICommandRunParams, ICommandShiftResult, ICommandToken, ICommandTokenType, ICommandTokenizeResult, ICommanderErrorKind, ICompletionCommandConfig, ICompletionMeta, ICompletionOptionMeta, ICompletionPaths, ICompletionShellType };
|
|
559
|
+
export { BashCompletion, Coerce, Command, CommanderError, CompletionCommand, FishCompletion, PwshCompletion, isDomain, isIp, isIpv4, isIpv6, logColorfulOption, logDateOption, logLevelOption, silentOption };
|
|
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/lib/types/node.d.ts
CHANGED
|
@@ -65,9 +65,9 @@ interface ICommandOptionConfig<T = unknown> {
|
|
|
65
65
|
apply?: (value: T, ctx: ICommandContext) => void;
|
|
66
66
|
}
|
|
67
67
|
/** Argument kind */
|
|
68
|
-
type ICommandArgumentKind = 'required' | 'optional' | 'variadic';
|
|
68
|
+
type ICommandArgumentKind = 'required' | 'optional' | 'variadic' | 'some';
|
|
69
69
|
/** Argument value type */
|
|
70
|
-
type ICommandArgumentType = 'string' | '
|
|
70
|
+
type ICommandArgumentType = 'string' | 'choice';
|
|
71
71
|
/**
|
|
72
72
|
* Positional argument configuration.
|
|
73
73
|
*
|
|
@@ -85,8 +85,10 @@ interface ICommandArgumentConfig<T = unknown> {
|
|
|
85
85
|
desc: string;
|
|
86
86
|
/** Argument kind: required / optional / variadic */
|
|
87
87
|
kind: ICommandArgumentKind;
|
|
88
|
-
/** Value type
|
|
89
|
-
type
|
|
88
|
+
/** Value type */
|
|
89
|
+
type: ICommandArgumentType;
|
|
90
|
+
/** Allowed values for choice type */
|
|
91
|
+
choices?: ReadonlyArray<string>;
|
|
90
92
|
/** Default value when not provided (only for optional arguments) */
|
|
91
93
|
default?: T;
|
|
92
94
|
/** Custom value transformation (takes precedence over type conversion) */
|
|
@@ -317,6 +319,11 @@ interface IHelpOptionLine {
|
|
|
317
319
|
sig: string;
|
|
318
320
|
desc: string;
|
|
319
321
|
}
|
|
322
|
+
/** Help argument line (internal) */
|
|
323
|
+
interface IHelpArgumentLine {
|
|
324
|
+
sig: string;
|
|
325
|
+
desc: string;
|
|
326
|
+
}
|
|
320
327
|
/** Help command line (internal) */
|
|
321
328
|
interface IHelpCommandLine {
|
|
322
329
|
name: string;
|
|
@@ -332,6 +339,7 @@ interface IHelpExampleLine {
|
|
|
332
339
|
interface IHelpData {
|
|
333
340
|
desc: string;
|
|
334
341
|
usage: string;
|
|
342
|
+
arguments: IHelpArgumentLine[];
|
|
335
343
|
options: IHelpOptionLine[];
|
|
336
344
|
commands: IHelpCommandLine[];
|
|
337
345
|
examples: IHelpExampleLine[];
|
|
@@ -361,6 +369,17 @@ interface ICompletionOptionMeta {
|
|
|
361
369
|
/** Allowed values */
|
|
362
370
|
choices?: string[];
|
|
363
371
|
}
|
|
372
|
+
/** Argument metadata for completion */
|
|
373
|
+
interface ICompletionArgumentMeta {
|
|
374
|
+
/** Argument name */
|
|
375
|
+
name: string;
|
|
376
|
+
/** Argument kind */
|
|
377
|
+
kind: ICommandArgumentKind;
|
|
378
|
+
/** Argument type */
|
|
379
|
+
type: ICommandArgumentType;
|
|
380
|
+
/** Allowed values (only for type='choice') */
|
|
381
|
+
choices?: string[];
|
|
382
|
+
}
|
|
364
383
|
/** Command metadata for completion */
|
|
365
384
|
interface ICompletionMeta {
|
|
366
385
|
/** Command name */
|
|
@@ -371,6 +390,8 @@ interface ICompletionMeta {
|
|
|
371
390
|
aliases: string[];
|
|
372
391
|
/** Options */
|
|
373
392
|
options: ICompletionOptionMeta[];
|
|
393
|
+
/** Positional arguments */
|
|
394
|
+
arguments: ICompletionArgumentMeta[];
|
|
374
395
|
/** Subcommands */
|
|
375
396
|
subcommands: ICompletionMeta[];
|
|
376
397
|
}
|
|
@@ -601,4 +622,4 @@ declare class PwshCompletion {
|
|
|
601
622
|
}
|
|
602
623
|
|
|
603
624
|
export { BashCompletion, Coerce, Command, CommanderError, CompletionCommand, FishCompletion, PwshCompletion, createBrowserCommandRuntime, createNodeCommandRuntime, getDefaultCommandRuntime, isDomain, isIp, isIpv4, isIpv6, logColorfulOption, logDateOption, logLevelOption, setDefaultCommandRuntime, silentOption };
|
|
604
|
-
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, ICommandRuntime, ICommandRuntimeStats, ICommandShiftResult, ICommandToken, ICommandTokenType, ICommandTokenizeResult, ICommanderErrorKind, ICompletionCommandConfig, ICompletionMeta, ICompletionOptionMeta, ICompletionPaths, ICompletionShellType, IHelpCommandLine, IHelpData, IHelpExampleLine, IHelpOptionLine, ISubcommandEntry };
|
|
625
|
+
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, ICommandRuntime, ICommandRuntimeStats, ICommandShiftResult, ICommandToken, ICommandTokenType, ICommandTokenizeResult, ICommanderErrorKind, ICompletionArgumentMeta, ICompletionCommandConfig, ICompletionMeta, ICompletionOptionMeta, ICompletionPaths, ICompletionShellType, IHelpArgumentLine, IHelpCommandLine, IHelpData, IHelpExampleLine, IHelpOptionLine, ISubcommandEntry };
|