You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🐛 fix: render option metavars, nargs and choices like usage (#353)
The option line built its own argument spec from `dest` and `metavar`,
and that spec disagreed with the usage line argparse prints two lines
above it. 🐛 A user metavar such as `<file>` or `path/to/dir` came out
upper-cased. `nargs=2` showed one `TWO` where usage shows `TWO TWO`;
`nargs="?"`, `"*"` and `REMAINDER` collapsed to a bare name; `choices`
were missing; a positional with `metavar=("SRC", "DST")` showed only
`SRC`.
Options now hand the action to argparse's own
`HelpFormatter._format_args`, the same call that produces the usage
line. The literal after the option name therefore reads `[OPT]`, `[MANY
...]`, `TWO TWO`, `...`, `{json,xml}` or the metavar as the author typed
it. Positionals join a tuple metavar with spaces for both the displayed
name and the anchor; otherwise they keep the metavar or `dest`, since
that name doubles as the reference target.
Rendered output changes for parsers that pass a lower-case metavar.
`--outdir out_dir` used to render as `OUT_DIR` and now renders as
`out_dir`, matching usage. Option anchors stay the same; a positional
with a tuple metavar moves from `#tool-SRC` to `#tool-SRC-DST`.
0 commit comments