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
Enhance argparse help output customizability #53861
Comments
I would like to be able to change argparse default strings so the first word is capitalized. In lieu of that, I propose the attached patch to 2.7 which changes them in the source code. |
Looks like "usage" is almost always lowercase in the programs I tried (ssh, svn, cat, etc.). So it probably wouldn't be a good idea to change the default. Seems like both this and bpo-9694 need a better way to customize the text in argparse mesages. As a temporary workaround for the group names, you can try: parser._optionals.title = "Optional arguments"
parser._positionals.title = "Positional arguments" I can't guarantee this will continue to work since it relies on internal details but at least it would work for the time being. |
2.7 is closed to new features and I cannot see making a non-bug change in a maintenance release that could break something. Should this be closed in favor of bpo-9694? (Or vice versa?). Perhaps one of the issues should be renamed something like "Improve argparse message customization". |
...
That sounds like a winner to me -Tom |
I'm moving this over to bpo-11695, which proposes support for a usage/help message template. To customize the argument group names, the recommended approach is to create your own argument groups, and only put arguments there, e.g.: parser = argparse.ArgumentParser(add_help=False)
flags = parser.add_argument_group('My Optional Arguments')
flags.add_argument('-h', '--help', action='help')
flags.add_argument('-v', action='version', version='1.3') Then you'll get just the "My Optional Arguments" heading. |
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:
The text was updated successfully, but these errors were encountered: