FJ-28: Colorize clap --help and error output with fj's palette #33

Merged
David merged 1 commit from feat/colorize-clap-help-FJ-28 into main 2026-05-31 15:12:28 +02:00
Owner

Summary

Resolves FJ-28: colorize clap's --help and error output using fj's existing palette.

fj --help (and every fj <area> --help) previously rendered monochrome because the root App command never set a clap Styles. This wires a HELP_STYLES constant that mirrors fj's own SpecialRender::fancy() colours and attaches it to App via #[command(styles = ...)].

Changes

  • crates/fj/src/main.rs: add HELP_STYLES (built from clap::builder::styling, which re-exports anstyle, so no new dependency) and #[command(styles = HELP_STYLES)] on App.

Palette mapping (from SpecialRender::fancy()):

  • header / usage: bold cyan
  • literal (flags, subcommands): green
  • placeholder (<COMMAND>, <HOST>): unstyled
  • error: bold red; invalid: red; valid: green

clap keeps the default ColorChoice::Auto, so color is emitted only on a TTY and is suppressed when piped or when NO_COLOR is set. The root command's styles propagate to every subcommand's help automatically.

Verification

  • cargo build -p forgejo-cli, cargo fmt --check, cargo clippy -p forgejo-cli: all pass.
  • TERM=xterm-256color TTY fj --help: section headers bold cyan, flags/commands green, <COMMAND> placeholder unstyled.
  • fj repo --help (subcommand) is colored the same way (styles propagate).
  • fj --notaflag error output uses bold red error: styling.
  • fj --help | cat and NO_COLOR=1 fj --help emit zero ANSI escapes.

Acceptance criteria

  • fj --help on a TTY colors section headers (bold cyan), flags/commands (green); placeholders unstyled.
  • fj <area> --help (e.g. fj repo --help) is colored the same way.
  • clap error output uses the red error styling.
  • fj --help | cat and NO_COLOR=1 fj --help emit no ANSI escapes.
  • No new dependency added; cargo build, cargo fmt --check, cargo clippy pass.
## Summary Resolves **FJ-28**: colorize clap's `--help` and error output using fj's existing palette. `fj --help` (and every `fj <area> --help`) previously rendered monochrome because the root `App` command never set a clap `Styles`. This wires a `HELP_STYLES` constant that mirrors fj's own `SpecialRender::fancy()` colours and attaches it to `App` via `#[command(styles = ...)]`. ## Changes - `crates/fj/src/main.rs`: add `HELP_STYLES` (built from `clap::builder::styling`, which re-exports anstyle, so no new dependency) and `#[command(styles = HELP_STYLES)]` on `App`. Palette mapping (from `SpecialRender::fancy()`): - `header` / `usage`: bold cyan - `literal` (flags, subcommands): green - `placeholder` (`<COMMAND>`, `<HOST>`): unstyled - `error`: bold red; `invalid`: red; `valid`: green clap keeps the default `ColorChoice::Auto`, so color is emitted only on a TTY and is suppressed when piped or when `NO_COLOR` is set. The root command's `styles` propagate to every subcommand's help automatically. ## Verification - `cargo build -p forgejo-cli`, `cargo fmt --check`, `cargo clippy -p forgejo-cli`: all pass. - `TERM=xterm-256color` TTY `fj --help`: section headers bold cyan, flags/commands green, `<COMMAND>` placeholder unstyled. - `fj repo --help` (subcommand) is colored the same way (styles propagate). - `fj --notaflag` error output uses bold red `error:` styling. - `fj --help | cat` and `NO_COLOR=1 fj --help` emit zero ANSI escapes. ## Acceptance criteria - [x] `fj --help` on a TTY colors section headers (bold cyan), flags/commands (green); placeholders unstyled. - [x] `fj <area> --help` (e.g. `fj repo --help`) is colored the same way. - [x] clap error output uses the red error styling. - [x] `fj --help | cat` and `NO_COLOR=1 fj --help` emit no ANSI escapes. - [x] No new dependency added; `cargo build`, `cargo fmt --check`, `cargo clippy` pass.
feat(cli): colorize clap --help and error output with fj's palette
All checks were successful
Check / fmt + clippy + build + tests (pull_request) Successful in 39s
Create release / Create release from merged PR (pull_request) Has been skipped
8cc1192219
clap rendered help and error output monochrome because the root `App` command never set a `Styles`. Define `HELP_STYLES` mirroring fj's own `SpecialRender::fancy()` colours (bold cyan headers and usage, green literals, red errors) using clap's re-exported anstyle (`clap::builder::styling`), and attach it via `#[command(styles = ...)]` on `App`. The root styles propagate to every subcommand's help.

clap keeps the default `ColorChoice::Auto`, so colour is emitted only on a TTY and suppressed when stdout is piped or `NO_COLOR` is set. No new dependency is added (anstyle is re-exported by clap). `cargo build`, `cargo fmt --check`, and `cargo clippy` all pass.

#FJ-28 State Done
David merged commit d80a5a124d into main 2026-05-31 15:12:28 +02:00
David deleted branch feat/colorize-clap-help-FJ-28 2026-05-31 15:12:28 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pandoras-box/forgejo-cli!33
No description provided.