Skip to content

CLI: improve command discoverability in --help and shell completion#1245

Merged
talagluck merged 4 commits into
mainfrom
cli-help-discoverability
Jul 16, 2026
Merged

CLI: improve command discoverability in --help and shell completion#1245
talagluck merged 4 commits into
mainfrom
cli-help-discoverability

Conversation

@talagluck

Copy link
Copy Markdown
Contributor

Cluster of three CLI discoverability follow-ups from #1205.

Changes

Nested command tree in --help (RND-12047)

Commander only lists a command's immediate children, so nested subgroups (organizations sites, spaces content pages, …) were invisible until you drilled in one level at a time. A new help-tree.ts walks the Commander tree at runtime and appends a "Command groups (nested)" section to every group's help — root, generated subgroups, and hand-written groups alike, so it stays in sync automatically.

Depth is capped at 1 level of nesting (subgroups only, no leaf verbs): it reveals e.g. sites under organizations from the top level while keeping gitbook --help bounded. Depth 2 was tried but explodes to 150+ lines on wide subtrees like sites (~30 nested collections) — the single TREE_DEPTH constant makes it trivial to revisit.

Hand-written commands in shell completion (RND-12064)

Completion was generated purely from the spec-derived tree, so hand-written groups' subcommands never tab-completed. Added a small static HAND_WRITTEN_COMPLETIONS map in generate-commands.ts (integration → new/dev/publish/unpublish/tail/check, openapi → publish) merged into the completion map. Kept next to a note to stay in sync with api-commands.ts.

integrationsintegration pointer (RND-12053)

People look under the plural integrations (raw API ops) for the build/publish lifecycle, which actually lives under the singular integration. gitbook integrations --help now points across.

Test plan

  • tsc --noEmit clean
  • bun test — 40 pass
  • Manually verified gitbook --help, gitbook organizations --help, gitbook integrations --help, and regenerated completion output
  • CI green

@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c230bf1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@gitbook/cli Patch

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

bun add https://pkg.pr.new/GitbookIO/integrations/@gitbook/api@1245

commit: c230bf1

@talagluck
talagluck marked this pull request as draft July 16, 2026 09:48
Shell completion was generated purely from the spec-derived command tree, so the
hand-written groups' subcommands never tab-completed. Add a static
HAND_WRITTEN_COMPLETIONS map (integration -> new/dev/publish/unpublish/tail/check,
openapi -> publish) merged into the completion map before the scripts are emitted.
…D-12047, RND-12053)

- Append a "Command groups (nested)" section to every group's --help so nested
  subgroups (e.g. organizations sites) are discoverable without drilling in.
  Root uses a compact one-line-per-group layout; subgroup pages use an indented
  tree. Attached generically by walking the Commander tree at runtime.
- Sort subcommands alphabetically (built-in list via configureHelp + the tree).
- Point `gitbook integrations --help` at the singular `gitbook integration`
  group for the build/publish lifecycle (new/dev/publish/...).
@talagluck
talagluck force-pushed the cli-help-discoverability branch from 5530b69 to 024f776 Compare July 16, 2026 10:38
@talagluck
talagluck marked this pull request as ready for review July 16, 2026 10:42
@talagluck
talagluck merged commit 17de11e into main Jul 16, 2026
14 checks passed
@talagluck
talagluck deleted the cli-help-discoverability branch July 16, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants