From f7295e33082a6bc3b79433b950eaf4c3e9adfcbc Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sat, 1 Aug 2026 05:39:37 +0800 Subject: [PATCH] fix(cli): route init --help to its own usage text (#3652) Co-Authored-By: Time Attakc <89218912+time-attack@users.noreply.github.com> --- src/cli.ts | 5 +++++ test/cli.test.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cli.ts b/src/cli.ts index 854c1de88..ba62f4147 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -107,6 +107,11 @@ const CLI_ONLY_SELF_HELP = new Set([ // `gbrain connect --help` prints its own usage (flags + examples) from // runConnect; route around the generic one-line short-circuit. 'connect', + // `gbrain init --help` prints its own usage from runInit; route around the + // generic one-line short-circuit (matches `connect`). Without this, `init` + // is in CLI_ONLY but not CLI_ONLY_SELF_HELP, so the dispatcher's generic + // short-circuit fires and the printInitHelp() guard in init.ts is dead code. + 'init', // #3390 — `gbrain migrate embeddings --help` / `gbrain retrieval-upgrade // --help` print the migration flags from runMigrateEmbeddings. `migrate` // (engine transfer) keeps its own dispatch too. diff --git a/test/cli.test.ts b/test/cli.test.ts index 121e6dd61..feafbd71d 100644 --- a/test/cli.test.ts +++ b/test/cli.test.ts @@ -195,7 +195,12 @@ describe('CLI dispatch integration', () => { }); const stdout = await new Response(proc.stdout).text(); const exitCode = await proc.exited; - expect(stdout).toContain('Usage: gbrain init'); + // init prints its OWN detailed help (printInitHelp), not the generic + // CLI-only one-line stub. Assert on markers unique to the real help... + expect(stdout).toContain('gbrain init [flags]'); + expect(stdout).toContain('ENGINE SELECTION'); + // ...and confirm the generic stub (printCliOnlyHelp) did NOT fire. + expect(stdout).not.toContain('run gbrain --help for the full command list'); expect(existsSync(join(home, '.gbrain', 'config.json'))).toBe(false); expect(exitCode).toBe(0); } finally {