fix(cli): per-command --help from the registry + slim global banner#576
Conversation
`stash <command> --help` short-circuited to the global banner, so no command had its own help — even the existing `auth` help was shadowed. Render command-specific help from the command-descriptor registry (`src/cli/registry.ts`) instead, keeping it in lockstep with `stash manifest`. - `stash eql install --help` / `stash auth login --help` → usage, summary, long description, flags, and examples for that command. - `stash eql --help` / `stash auth --help` → the group's subcommands with a pointer to their own `--help`. - Honour `-h` after a command too (`parseArgs` only recognised the long `--help`, so `stash eql install -h` silently fell through). - Slim the global banner: drop the six hand-maintained per-command flag sections (now redundant with per-command help) and trim the examples; it lists the commands and points at `<command> --help`. Tests: new unit coverage for the renderer (`src/cli/help.ts`) and e2e coverage for the routing; repointed the auth/impl banner assertions at the per-command help that now owns that detail.
🦋 Changeset detectedLatest commit: cbece82 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📝 WalkthroughWalkthroughThis PR introduces registry-driven per-command ChangesPer-command help rendering
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant mainTs as main.ts run()
participant renderCommandHelp
participant registry
User->>mainTs: stash <command> --help / -h
mainTs->>mainTs: parseArgs sets flags.help
mainTs->>mainTs: build command path from command/subcommand
mainTs->>renderCommandHelp: renderCommandHelp(path, STASH)
renderCommandHelp->>registry: lookup exact or prefix match
registry-->>renderCommandHelp: descriptor(s) or none
renderCommandHelp-->>mainTs: rendered help text or null
mainTs-->>User: print command help or fallback global HELP banner
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR fixes stash <command> --help so it renders command-specific help (from the CLI command-descriptor registry) instead of always showing the global banner, and trims the global stash --help output accordingly.
Changes:
- Add a registry-driven per-command help renderer (
renderCommandHelp) and route--help/-hto it after command dispatch is known. - Normalize short flags
-h/-vintoflags.help/flags.versionso help/version work after a command path. - Add unit + E2E coverage for per-command help routing and update existing E2E assertions to match the slimmer global banner.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/cli/src/bin/main.ts | Routes --help to per-command renderer post-dispatch; normalizes -h/-v; slims global HELP banner content. |
| packages/cli/src/cli/help.ts | New registry-driven renderer for leaf-command help and command-group listings. |
| packages/cli/src/cli/registry.ts | Updates header comment to reflect registry now drives both manifest and per-command help. |
| packages/cli/src/cli/tests/help.test.ts | New unit tests for help rendering behavior (leaf, group, env/default annotations, fallback). |
| packages/cli/tests/e2e/command-help.e2e.test.ts | New E2E tests validating routing behavior and fallback to global help. |
| packages/cli/tests/e2e/auth-non-interactive.e2e.test.ts | Updates assertions to reflect slim global banner + per-command help ownership. |
| packages/cli/tests/e2e/impl-non-tty.e2e.test.ts | Updates assertion to check impl --help output for --target docs. |
| .changeset/stash-cli-per-command-help.md | Changeset describing the help behavior change and global banner slimming. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Low-risk, help/docs focused. Thoroughly AI reviewed and checked by author. |
What
stash <command> --helpdisplayed the global banner instead of help for that command. Reported from testing the 0.17 CLI:Root cause:
run()inbin/main.tscheckedflags.helpbefore dispatching, so--helpalways rendered the globalHELPstring — shadowing even theauthcommand's own existing help.Changes
src/cli/help.tsrendersstash <command> --helpfrom the command-descriptor registry (src/cli/registry.ts) — the same sourcestash manifestuses, so they can't drift.eql install,auth login,init) → usage, summary, long description, anOptions:table (with<value>placeholders,(default: …)andAlso settable via ENV.annotations), andExamples:.eql,auth,db,encrypt,schema) → a subcommand listing that points at each subcommand's own--help.-hworks after a command too.parseArgsonly recognised the long--help;stash eql install -hsilently fell through and tried to run the command. Short-h/-vare now normalised toflags.help/flags.version.stash --help) went from ~120 to ~45 lines: command list + a pointer to<command> --help.registry.tsheader comment — the registry now feeds bothstash manifestand per-command--help; the only hand-maintained surface left is the banner's command list.This is the documented follow-on to the manifest/registry work (
docs/plans/cli-help-and-manifest.md), which noted--helpwould later render from the descriptors.Before / after
Tests
src/cli/__tests__/help.test.ts(new, 8) — renderer unit tests.tests/e2e/command-help.e2e.test.ts(new, 5) — e2e routing against the built binary: group listing, full command help, the-hshort flag, and both fallback paths.All 390 unit + 49 e2e tests pass; Biome clean. Pre-existing unrelated
tscerrors (auth WASM types, backfill, etc.) are untouched.Changeset:
stashpatch.Closes #577.
Summary by CodeRabbit
New Features
stash <command> --helpnow shows help specific to that command, including usage, options, examples, and subcommand lists where relevant.-hnow works after a command path, such asstash eql install -h.Bug Fixes
stash --helpscreen now points users to command-specific help instead of listing every flag inline.