Format argparse help with rich-argparse#118
Merged
Merged
Conversation
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>
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.
Summary
rich_argparse.RawDescriptionRichHelpFormatter(via aPicoptHelpFormattersubclass) sopicopt --helpis colorized.PNG,ZIP,WEBP,JPEG, …) under themetavarnamed group, so format names mentioned inside help text share the color of their correspondingFORMATS/EXTRA_FORMATS/CONVERT_TOmetavars. The default rich-argparse highlight already handles--optionreferences in help text.Console. rich-argparse renders descriptions and epilogs throughconsole.use_theme(Theme(self.styles)), so the epilog uses[argparse.groups],[argparse.prog], and[argparse.args]to keep the section header, program name, anddoctorsubcommand visually consistent with the rest of the rendered help.char+stylestraight frompicopt.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.) theFORMATSmetavar color and the format names listed in the help text body. rich-argparse'shighlightsmechanism makes that link first-class.Notes for reviewers
rich-argparse~=1.8(added topyproject.toml/uv.lock).from rich.console import Consoleimport is dropped frompicopt/cli.py—Consolewas only used for the old ANSI-capture path.PicoptHelpFormatter.highlightsis computed at class-definition time fromregistry.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 skippedpicopt --helprendered manually; format names in help text and the epilog headers/prog/subcommand all pick up the formatter theme🤖 Generated with Claude Code