@guanghechen/commander 4.6.0 → 4.7.1

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.
@@ -92,54 +92,16 @@ 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
- }
131
95
  /** Command configuration */
132
96
  interface ICommandConfig {
133
97
  /** Command name (only for root command) */
134
98
  name?: string;
135
99
  /** Command description */
136
100
  desc: string;
137
- /** Version (for built-in --version on this command) */
101
+ /** Version (for root --version) */
138
102
  version?: string;
139
- /** Built-in features configuration */
140
- builtin?: boolean | ICommandBuiltinConfig;
141
- /** Command-level preset defaults */
142
- preset?: ICommandPresetConfig;
103
+ /** Enable built-in "help" subcommand */
104
+ help?: boolean;
143
105
  /** Default reporter for this command */
144
106
  reporter?: IReporter;
145
107
  }
@@ -148,28 +110,21 @@ interface ICommand {
148
110
  readonly name: string | undefined;
149
111
  readonly description: string;
150
112
  readonly version: string | undefined;
151
- readonly builtin: ICommandConfig['builtin'] | undefined;
152
- readonly preset: ICommandPresetConfig | undefined;
153
113
  readonly parent: ICommand | undefined;
154
114
  readonly options: ICommandOptionConfig[];
155
115
  readonly arguments: ICommandArgumentConfig[];
156
- readonly examples: ICommandExample[];
157
116
  readonly subcommands: Map<string, ICommand>;
158
117
  }
159
118
  /** Execution context */
160
119
  interface ICommandContext {
161
120
  /** Current command node */
162
121
  cmd: ICommand;
163
- /** Command chain from root to leaf */
164
- chain: ICommand[];
165
- /** Effective environment variables */
122
+ /** Environment variables */
166
123
  envs: Record<string, string | undefined>;
167
- /** Built-in control hit status */
168
- controls: ICommandControls;
169
- /** Input source snapshots */
170
- sources: ICommandInputSources;
171
124
  /** Reporter instance */
172
125
  reporter: IReporter;
126
+ /** Original argv */
127
+ argv: string[];
173
128
  }
174
129
  /** Action callback parameters */
175
130
  interface ICommandActionParams {
@@ -198,29 +153,11 @@ type ICommandParsedOpts = Record<string, unknown>;
198
153
  /** Parsed arguments record */
199
154
  type ICommandParsedArgs = Record<string, unknown>;
200
155
  /** Route stage result */
201
- interface ICommandRouteResult<TCommand = ICommand> {
156
+ interface ICommandRouteResult {
202
157
  /** Command chain from root to leaf */
203
- chain: TCommand[];
158
+ chain: ICommand[];
204
159
  /** Remaining argv after routing */
205
160
  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>;
224
161
  }
225
162
  /** Tokenize stage result */
226
163
  interface ICommandTokenizeResult {
@@ -254,71 +191,8 @@ interface ICommandParseResult {
254
191
  /** Raw argument strings */
255
192
  rawArgs: string[];
256
193
  }
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
- }
320
194
  /** Error kinds for command parsing */
321
- type ICommanderErrorKind = 'InvalidOptionFormat' | 'InvalidNegativeOption' | 'NegativeOptionWithValue' | 'NegativeOptionType' | 'UnknownOption' | 'UnknownSubcommand' | 'UnexpectedArgument' | 'MissingValue' | 'InvalidType' | 'UnsupportedShortSyntax' | 'OptionConflict' | 'MissingRequired' | 'InvalidChoice' | 'InvalidBooleanValue' | 'MissingRequiredArgument' | 'TooManyArguments' | 'ConfigurationError';
195
+ type ICommanderErrorKind = 'InvalidOptionFormat' | 'InvalidNegativeOption' | 'NegativeOptionWithValue' | 'NegativeOptionType' | 'UnknownOption' | 'UnexpectedArgument' | 'MissingValue' | 'InvalidType' | 'UnsupportedShortSyntax' | 'OptionConflict' | 'MissingRequired' | 'InvalidChoice' | 'InvalidBooleanValue' | 'MissingRequiredArgument' | 'TooManyArguments' | 'ConfigurationError';
322
196
  /** Commander error with structured information */
323
197
  declare class CommanderError extends Error {
324
198
  readonly kind: ICommanderErrorKind;
@@ -369,13 +243,13 @@ interface ICompletionCommandConfig {
369
243
  /** Program name for completion scripts (defaults to root.name) */
370
244
  programName?: string;
371
245
  /** Default completion file paths for each shell */
372
- paths?: Partial<ICompletionPaths>;
246
+ paths: ICompletionPaths;
373
247
  }
374
248
 
375
249
  /**
376
250
  * Command class - CLI command builder with fluent API
377
251
  *
378
- * Execution flow: route → control-scan → run-control(run) → preset → tokenize → resolve → parse → run
252
+ * Execution flow: route → tokenize → resolve → parse → run
379
253
  *
380
254
  * @module @guanghechen/commander
381
255
  */
@@ -386,48 +260,20 @@ declare class Command implements ICommand {
386
260
  get name(): string | undefined;
387
261
  get description(): string;
388
262
  get version(): string | undefined;
389
- get builtin(): ICommandConfig['builtin'] | undefined;
390
- get preset(): ICommandPresetConfig | undefined;
391
263
  get parent(): Command | undefined;
392
264
  get options(): ICommandOptionConfig[];
393
265
  get arguments(): ICommandArgumentConfig[];
394
- get examples(): ICommandExample[];
395
266
  get subcommands(): Map<string, ICommand>;
396
267
  option<T>(opt: ICommandOptionConfig<T>): this;
397
268
  argument<T>(arg: ICommandArgumentConfig<T>): this;
398
269
  action(fn: ICommandAction): this;
399
- example(title: string, usage: string, desc: string): this;
400
270
  subcommand(name: string, cmd: Command): this;
401
271
  run(params: ICommandRunParams): Promise<void>;
402
- parse(params: ICommandRunParams): Promise<ICommandParseResult>;
272
+ parse(params: ICommandRunParams): ICommandParseResult;
403
273
  formatHelp(): string;
404
274
  getCompletionMeta(): ICompletionMeta;
405
275
  }
406
276
 
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
-
431
277
  /**
432
278
  * Shell completion generators
433
279
  *
@@ -455,7 +301,7 @@ declare function isDomain(rawValue: string): boolean;
455
301
  * ```
456
302
  */
457
303
  declare class CompletionCommand extends Command {
458
- constructor(root: Command, config?: ICompletionCommandConfig);
304
+ constructor(root: Command, config: ICompletionCommandConfig);
459
305
  }
460
306
  declare class BashCompletion {
461
307
  #private;
@@ -509,28 +355,6 @@ declare class PwshCompletion {
509
355
  * ```
510
356
  */
511
357
  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>;
534
358
  /**
535
359
  * Pre-defined --silent option for suppressing non-error output.
536
360
  *
@@ -556,5 +380,5 @@ declare const logColorfulOption: ICommandOptionConfig<boolean>;
556
380
  */
557
381
  declare const silentOption: ICommandOptionConfig<boolean>;
558
382
 
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 };
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 };