Skip to content

Format argparse help with rich-argparse#118

Merged
ajslater merged 1 commit into
developfrom
claude/goofy-williamson-6ec727
May 5, 2026
Merged

Format argparse help with rich-argparse#118
ajslater merged 1 commit into
developfrom
claude/goofy-williamson-6ec727

Conversation

@ajslater
Copy link
Copy Markdown
Owner

@ajslater ajslater commented May 5, 2026

Summary

  • Switch picopt's CLI to rich_argparse.RawDescriptionRichHelpFormatter (via a PicoptHelpFormatter subclass) so picopt --help is colorized.
  • Add one extra highlight regex matching every registered format string (PNG, ZIP, WEBP, JPEG, …) under the metavar named group, so format names mentioned inside help text share the color of their corresponding FORMATS / EXTRA_FORMATS / CONVERT_TO metavars. The default rich-argparse highlight already handles --option references in help text.
  • Rewrite the dot-color-key / doctor-mode epilog as Rich markup instead of capturing ANSI from a Console. rich-argparse renders descriptions and epilogs through console.use_theme(Theme(self.styles)), so the epilog uses [argparse.groups], [argparse.prog], and [argparse.args] to keep the section header, program name, and doctor subcommand visually consistent with the rest of the rendered help.
  • The progress-char dots themselves still pull char + style straight from picopt.log.styles.MARKS, so the legend keeps its existing per-outcome colors.

Why

The previous epilog rendered Rich markup through a captured Console, then handed argparse a string of raw ANSI escape codes. That worked, but the rest of the help was uncolored, and there was no relationship between (e.g.) the FORMATS metavar color and the format names listed in the help text body. rich-argparse's highlights mechanism makes that link first-class.

Notes for reviewers

  • New runtime dependency: rich-argparse~=1.8 (added to pyproject.toml / uv.lock).
  • from rich.console import Console import is dropped from picopt/cli.pyConsole was only used for the old ANSI-capture path.
  • PicoptHelpFormatter.highlights is computed at class-definition time from registry.all_format_strs() (which is @cache'd), so there's no per-invocation cost.

Test plan

  • make lint (clean)
  • make ty (clean)
  • pytest — 150 passed, 6 skipped
  • picopt --help rendered manually; format names in help text and the epilog headers/prog/subcommand all pick up the formatter theme

🤖 Generated with Claude Code

Switch picopt's CLI to RawDescriptionRichHelpFormatter so the help
output is colorized. A PicoptHelpFormatter subclass adds one extra
highlight regex matching every registered format string (PNG, ZIP,
WEBP, …) under the `metavar` named group, so format names mentioned
inside help text share the color of their corresponding FORMATS /
EXTRA_FORMATS / CONVERT_TO metavars.

Rewrite the dot-color-key / doctor-mode epilog as Rich markup instead
of capturing ANSI from a Console. rich-argparse renders descriptions
and epilogs through `console.use_theme(Theme(self.styles))`, so the
epilog can use [argparse.groups], [argparse.prog], and [argparse.args]
to keep its section header, program name, and `doctor` subcommand
visually consistent with how the rest of the help is rendered.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ajslater ajslater merged commit 70f810d into develop May 5, 2026
2 checks passed
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.

1 participant