@guanghechen/commander 4.6.0 → 4.7.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.
@@ -128,6 +128,23 @@ interface ICommandPresetConfig {
128
128
  /** Default preset envs file */
129
129
  env?: string;
130
130
  }
131
+ /** Runtime file stats abstraction */
132
+ interface ICommandRuntimeStats {
133
+ isDirectory(): boolean;
134
+ }
135
+ /** Runtime abstraction for environment-dependent operations */
136
+ interface ICommandRuntime {
137
+ /** Current working directory */
138
+ cwd(): string;
139
+ /** Path absolute check */
140
+ isAbsolute(filepath: string): boolean;
141
+ /** Resolve paths into an absolute path */
142
+ resolve(...paths: string[]): string;
143
+ /** Read UTF-8 text file */
144
+ readFile(filepath: string): Promise<string>;
145
+ /** Stat file system entry */
146
+ stat(filepath: string): Promise<ICommandRuntimeStats>;
147
+ }
131
148
  /** Command configuration */
132
149
  interface ICommandConfig {
133
150
  /** Command name (only for root command) */
@@ -142,6 +159,8 @@ interface ICommandConfig {
142
159
  preset?: ICommandPresetConfig;
143
160
  /** Default reporter for this command */
144
161
  reporter?: IReporter;
162
+ /** Runtime adapter for environment-dependent operations */
163
+ runtime?: ICommandRuntime;
145
164
  }
146
165
  /** Command interface */
147
166
  interface ICommand {
@@ -372,6 +391,14 @@ interface ICompletionCommandConfig {
372
391
  paths?: Partial<ICompletionPaths>;
373
392
  }
374
393
 
394
+ /**
395
+ * Node runtime adapter
396
+ *
397
+ * @module @guanghechen/commander
398
+ */
399
+
400
+ declare function createNodeCommandRuntime(): ICommandRuntime;
401
+
375
402
  /**
376
403
  * Command class - CLI command builder with fluent API
377
404
  *
@@ -428,51 +455,6 @@ declare function isIpv6(rawValue: string): boolean;
428
455
  declare function isIp(rawValue: string): boolean;
429
456
  declare function isDomain(rawValue: string): boolean;
430
457
 
431
- /**
432
- * Shell completion generators
433
- *
434
- * @module @guanghechen/commander
435
- */
436
-
437
- /**
438
- * Built-in completion command that generates shell completion scripts.
439
- *
440
- * @example
441
- * ```typescript
442
- * const root = new Command({ name: 'mycli', desc: 'My CLI' })
443
- * root.subcommand('completion', new CompletionCommand(root, {
444
- * paths: {
445
- * bash: `~/.local/share/bash-completion/completions/mycli`,
446
- * fish: `~/.config/fish/completions/mycli.fish`,
447
- * pwsh: `~/.config/powershell/Microsoft.PowerShell_profile.ps1`,
448
- * }
449
- * }))
450
- *
451
- * // Usage:
452
- * // mycli completion --bash > ~/.local/share/bash-completion/completions/mycli
453
- * // mycli completion --fish --write (writes to default path)
454
- * // mycli completion --fish --write /custom/path.fish
455
- * ```
456
- */
457
- declare class CompletionCommand extends Command {
458
- constructor(root: Command, config?: ICompletionCommandConfig);
459
- }
460
- declare class BashCompletion {
461
- #private;
462
- constructor(meta: ICompletionMeta, programName: string);
463
- generate(): string;
464
- }
465
- declare class FishCompletion {
466
- #private;
467
- constructor(meta: ICompletionMeta, programName: string);
468
- generate(): string;
469
- }
470
- declare class PwshCompletion {
471
- #private;
472
- constructor(meta: ICompletionMeta, programName: string);
473
- generate(): string;
474
- }
475
-
476
458
  /**
477
459
  * Pre-defined common options for @guanghechen/commander
478
460
  *
@@ -556,5 +538,67 @@ declare const logColorfulOption: ICommandOptionConfig<boolean>;
556
538
  */
557
539
  declare const silentOption: ICommandOptionConfig<boolean>;
558
540
 
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 };
541
+ /**
542
+ * Browser runtime adapter
543
+ *
544
+ * @module @guanghechen/commander
545
+ */
546
+
547
+ declare function createBrowserCommandRuntime(): ICommandRuntime;
548
+
549
+ /**
550
+ * Runtime adapters
551
+ *
552
+ * @module @guanghechen/commander
553
+ */
554
+
555
+ declare function getDefaultCommandRuntime(): ICommandRuntime;
556
+ declare function setDefaultCommandRuntime(runtime: ICommandRuntime): void;
557
+
558
+ /**
559
+ * Shell completion generators
560
+ *
561
+ * @module @guanghechen/commander
562
+ */
563
+
564
+ /**
565
+ * Built-in completion command that generates shell completion scripts.
566
+ *
567
+ * @example
568
+ * ```typescript
569
+ * const root = new Command({ name: 'mycli', desc: 'My CLI' })
570
+ * root.subcommand('completion', new CompletionCommand(root, {
571
+ * paths: {
572
+ * bash: `~/.local/share/bash-completion/completions/mycli`,
573
+ * fish: `~/.config/fish/completions/mycli.fish`,
574
+ * pwsh: `~/.config/powershell/Microsoft.PowerShell_profile.ps1`,
575
+ * }
576
+ * }))
577
+ *
578
+ * // Usage:
579
+ * // mycli completion --bash > ~/.local/share/bash-completion/completions/mycli
580
+ * // mycli completion --fish --write (writes to default path)
581
+ * // mycli completion --fish --write /custom/path.fish
582
+ * ```
583
+ */
584
+ declare class CompletionCommand extends Command {
585
+ constructor(root: Command, config?: ICompletionCommandConfig);
586
+ }
587
+ declare class BashCompletion {
588
+ #private;
589
+ constructor(meta: ICompletionMeta, programName: string);
590
+ generate(): string;
591
+ }
592
+ declare class FishCompletion {
593
+ #private;
594
+ constructor(meta: ICompletionMeta, programName: string);
595
+ generate(): string;
596
+ }
597
+ declare class PwshCompletion {
598
+ #private;
599
+ constructor(meta: ICompletionMeta, programName: string);
600
+ generate(): string;
601
+ }
602
+
603
+ 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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guanghechen/commander",
3
- "version": "4.6.0",
3
+ "version": "4.7.0",
4
4
  "description": "A minimal, type-safe command-line interface builder with fluent API",
5
5
  "author": {
6
6
  "name": "guanghechen",
@@ -20,17 +20,20 @@
20
20
  ],
21
21
  "type": "module",
22
22
  "exports": {
23
- ".": {
24
- "types": "./lib/types/index.d.ts",
25
- "source": "./src/index.ts",
26
- "import": "./lib/esm/index.mjs",
27
- "require": "./lib/cjs/index.cjs"
23
+ ".": null,
24
+ "./browser": {
25
+ "types": "./lib/types/browser.d.ts",
26
+ "source": "./src/runtime/browser/entry.ts",
27
+ "import": "./lib/esm/browser.mjs",
28
+ "require": "./lib/cjs/browser.cjs"
29
+ },
30
+ "./node": {
31
+ "types": "./lib/types/node.d.ts",
32
+ "source": "./src/runtime/node/index.ts",
33
+ "import": "./lib/esm/node.mjs",
34
+ "require": "./lib/cjs/node.cjs"
28
35
  }
29
36
  },
30
- "source": "./src/index.ts",
31
- "main": "./lib/cjs/index.cjs",
32
- "module": "./lib/esm/index.mjs",
33
- "types": "./lib/types/index.d.ts",
34
37
  "license": "MIT",
35
38
  "files": [
36
39
  "lib/",
@@ -41,8 +44,8 @@
41
44
  "README.md"
42
45
  ],
43
46
  "dependencies": {
44
- "@guanghechen/env": "^2.0.2",
45
- "@guanghechen/reporter": "^3.3.0"
47
+ "@guanghechen/reporter": "^3.3.0",
48
+ "@guanghechen/env": "^2.0.2"
46
49
  },
47
50
  "scripts": {
48
51
  "build": "rollup -c ../../rollup.config.mjs",