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
[argparse] Add parameter to sort help output arguments #83960
Comments
1 import argparse It would be nice if we could have the option to alphabetically sort the tokens in the optional and positional arguments sections of the help message in order to find an argument more quickly when reading long help descriptions. Currently we output the following, when the above program is ran: positional arguments: optional arguments: I'm proposing that we provide a mechanism to allow alphabetical ordering of both sections, like so: positional arguments: optional arguments: I've chosen to leave -h as an exception, as it will always be there as an optional argument, but it could easily be treated no different. We could provide an optional argument to print_help(sort=False) as a potential approach. If this is something that the maintainer's would be willing to accept, I'd love to take it on and prepare a patch. |
Thanks for the suggestion, but I am going to decline. Since the parser remembers the order the arguments were added, the programmer already has complete control over the ordering of arguments. |
That makes sense. For what it's worth, the use-case that inspired this was for commands with a lot of optional arguments in a company where a large amount of contributors (who may not be aware of an effort to order the arguments in the source code) were able to make changes to the command. I understand that isn't a particularly compelling reason though, as it can be addressed by other means -- increasing diligence at the code review stage, commit hooks, testing, etc. Thanks for taking a look Raymond. |
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: