New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "metavar" argument to add_subparsers() in argparse #58247
Comments
Currently, using add_subparsers() means that the entire list of subcommands is added to the main usage message. This gets rather unwieldy when there are a lot of subcommands. It would be nice if the add_subparsers() method accepted a "metavar" argument that would be substituted into the usage string instead of using the subparser list directly. |
Have you tried setting the metavar property on the return value of add_subparsers()? I tried this, and it seems to work. It looks like the logic for _metavar_formatter() is the same no matter what the action type (specifically _SubParsersAction in this case): http://hg.python.org/cpython/file/e81cad0c722a/Lib/argparse.py#l554 |
Actually, it looks like add_subparsers() may already support passing a metavar argument, but it's just not documented? |
Thanks to bpo-11807, the documentation now lists “metavar”. (However, it looks like a positional argument, rather than keyword-only, and its use seems to be discouraged, but those issues are not specific to “metavar”.) Some points specific to “metavar” that I think could be clarified:
|
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
The text was updated successfully, but these errors were encountered: