@gajae-code/utils 0.4.1 → 0.4.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.
@@ -69,6 +69,7 @@ export interface CommandCtor {
69
69
  examples?: string[];
70
70
  flags?: Record<string, FlagDescriptor>;
71
71
  args?: Record<string, ArgDescriptor>;
72
+ delegateHelp?: boolean;
72
73
  }
73
74
  /** Configuration passed to every command instance and help renderers. */
74
75
  export interface CliConfig {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@gajae-code/utils",
4
- "version": "0.4.1",
4
+ "version": "0.4.2",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://gaebal-gajae.dev",
7
7
  "author": "Yeachan-Heo",
@@ -31,7 +31,7 @@
31
31
  "fmt": "biome format --write ."
32
32
  },
33
33
  "dependencies": {
34
- "@gajae-code/natives": "0.4.1",
34
+ "@gajae-code/natives": "0.4.2",
35
35
  "beautiful-mermaid": "^1.1.3",
36
36
  "handlebars": "^4.7.9",
37
37
  "winston": "^3.19.0",
package/src/cli.ts CHANGED
@@ -111,6 +111,7 @@ export interface CommandCtor {
111
111
  examples?: string[];
112
112
  flags?: Record<string, FlagDescriptor>;
113
113
  args?: Record<string, ArgDescriptor>;
114
+ delegateHelp?: boolean;
114
115
  }
115
116
 
116
117
  /** Configuration passed to every command instance and help renderers. */
@@ -392,16 +393,22 @@ export async function run(opts: RunOptions): Promise<void> {
392
393
  return;
393
394
  }
394
395
 
395
- // Per-command help
396
+ // Per-command help. Commands with nested subcommands can opt into receiving
397
+ // help flags themselves so `cmd subcommand --help` can render subcommand help.
396
398
  if (commandArgv.includes("--help") || commandArgv.includes("-h")) {
397
- const config = await loadAllCommands(opts);
398
- // Resolve aliases for help too
399
399
  const entry = findEntry(opts.commands, commandId);
400
- const Cmd = entry ? config.commands.get(entry.name) : undefined;
401
- if (Cmd) {
402
- renderCommandHelp(bin, entry!.name, Cmd);
403
- } else {
400
+ if (!entry) {
404
401
  process.stderr.write(`Unknown command: ${commandId}\n`);
402
+ return;
403
+ }
404
+ const Cmd = await entry.load();
405
+ if (Cmd.delegateHelp) {
406
+ const config: CliConfig = { bin, version, commands: new Map([[entry.name, Cmd]]) };
407
+ const instance = new Cmd(commandArgv, config);
408
+ await instance.run();
409
+ } else {
410
+ const config = await loadAllCommands(opts);
411
+ renderCommandHelp(bin, entry.name, config.commands.get(entry.name) ?? Cmd);
405
412
  }
406
413
  return;
407
414
  }