CLI: custom root-help renderer with real grouped sections#171
Merged
Conversation
clap 4 only renders subcommands under one flat `Commands:` header. The
previous PR added a `long_about` "Quick Reference" block above the flat
list, which felt duplicative — and only showed on `--help`, not `-h`.
This swaps that for a custom renderer at the root level only. `rift`,
`rift -h`, and `rift --help` all now produce:
Account:
init …
login …
…
Resources:
links …
…
Billing:
subscribe …
…
Meta:
version …
update …
completions …
Subcommand help (`rift links --help`, `rift team rm -h`, …) is
unchanged — clap's default still handles those, which is the right
default for nested help.
How it works:
- Each command's `#[command(display_order = N)]` lives in a numeric
range (10–19 Account, 20–29 Resources, 30–39 Billing, 40–99 Meta).
- `print_grouped_help` introspects `Cli::command()`, partitions
subcommands by range, renders each group with a header.
- Intercepted before `clap::parse()` so bare / -h / --help all hit it.
- Falls into an "Other" section for any command outside known ranges,
so commands added without a display_order are still visible.
Drops the now-redundant `long_about` block.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the previous PR's "Quick Reference + flat command list" with actual grouped sections in the Commands list itself. No duplication.
Before vs after
Before (PR #170 — Quick Reference block above, flat list below):
And a separate "Quick reference" block only on
--help.After:
rift,rift -h, andrift --helpall produce the same output. Subcommand help (rift links --help,rift team rm -h) is unchanged — clap handles those.How it works
clap 4 doesn't natively group subcommands. The workaround:
Commandvariant carries#[command(display_order = N)].Nlives in a numeric range that maps to a group:10–19 Account,20–29 Resources,30–39 Billing,40–99 Meta.print_grouped_help()introspectsCli::command(), partitions subcommands by range, renders each group with a header.argvcheck beforeclap::parse()intercepts the root-help cases and callsprint_grouped_help().Maintenance cost: each new command picks an appropriate
display_orderfrom the right group's range. Forgetting? It falls into an "Other:" section, still visible.Test plan
cargo fmt --check,cargo clippy -D warnings,cargo testonclient/clirift(bare),rift -h,rift --helpall render the grouped outputrift links --helpunchanged (clap default)rift links list -hunchanged (clap default, nested)rift -V/rift --versionstill works (clap handles before our intercept)rift-cli-v0.2.4. Afterrift update, confirmriftshows grouped help.🤖 Generated with Claude Code