CLI: catch rift help; style grouped help with colors#172
Merged
Conversation
Two follow-ups on the grouped-help renderer:
1. `rift help` was still hitting clap's built-in `help` subcommand,
which prints the flat clap-default output. Extend the argv-prefix
intercept to catch `help` alongside `-h` / `--help`. `rift help
<subcommand>` still falls through to clap (correctly — nested help
is what clap handles well).
2. Styling pass via the `console` crate (already a dep):
- Group headers (Account: / Resources: / Billing: / Meta:): yellow,
bold — pop-out so the grouping is the visual anchor.
- Command names (init, links, …): cyan, bold — matches the
convention from gh, kubectl, fly.
- "Usage:" / "Options:": bold (no color) — clap's default look.
- "Aliases: …" hint and footer "Run …": dim — they're context,
not action.
`console::colors_enabled()` gates the entire style block: when stdout
isn't a TTY or `NO_COLOR` is set, every style collapses to plain text
so piped / file / CI output stays clean.
Padding bug avoided: the styled-string `.len()` includes ANSI escape
bytes, so the alignment uses the raw name length and prepends spaces
manually. Pulled the per-row rendering into a `print_row` helper since
both the group loop and the "Other:" fallback do the same thing.
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.
Two small follow-ups on #171 (the grouped-help renderer).
1.
rift helpnow hits the grouped rendererclap auto-adds a built-in
helpsubcommand that bypasses our argv-prefix intercept.rift helpwas still printing the flat clap-default Commands list. Extends the intercept to catchhelpalongside-h/--help.rift help <subcommand>still falls through to clap correctly — nested help is what clap handles well.2. Styling pass via
consolecrate (already a dep)Before this PR every line was plain text; now there's visual hierarchy:
Account:/Resources:/Billing:/Meta:): yellow + bold — anchors the eye to the structure.init,links,subscribe, …): cyan + bold — matchesgh/kubectl/fly.Usage:/Options:: bold (no color) — same shape clap uses.Aliases: …hint and footer: dim — context, not action.console::colors_enabled()gates the entire style block:NO_COLOR, non-TTY stdout, and CI environments all get plain text (verified by piping intocat).Padding gotcha worth noting
ANSI escape codes inflate
String::len(), so right-padding a styled name with"{:<12}"produces visibly broken alignment (the escape bytes count toward the width). The fix is to measure the raw name, build the pad string manually, then emit the styled name with the pad appended. Pulled into aprint_rowhelper since both the group loop and the "Other:" fallback share the same shape.Test plan
cargo fmt --check,cargo clippy -D warnings,cargo testonclient/clirift helpproduces the grouped renderer outputrift,rift -h,rift --helpstill produce the same outputrift --help | catstrips all ANSI (piped → no colors)rift links --helpunchanged (clap default, scoped)rift update, visually confirm yellow group headers + cyan command names render in a real terminal.🤖 Generated with Claude Code