New submission from brian.gallagher <oss.brn...@gmail.com>:
1 import argparse 2 3 parser = argparse.ArgumentParser(description='Test') 4 parser.add_argument('c', help='token c') 5 parser.add_argument('b', help='token b') 6 parser.add_argument('d', help='token d') 7 parser.add_argument('-a', help='token a') 8 parser.add_argument('-z', help='token z') 9 parser.add_argument('-f', help='token f', required=True) 10 parser.print_help() 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: c token c b token b d token d optional arguments: -h, --help show this help message and exit -a A token a -z Z token z -f F token f I'm proposing that we provide a mechanism to allow alphabetical ordering of both sections, like so: positional arguments: b token b c token c d token d optional arguments: -h, --help show this help message and exit -a A token a -f F token f -z Z token z 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. ---------- components: Library (Lib) messages: 362849 nosy: brian.gallagher priority: normal severity: normal status: open title: [argparse] Add parameter to sort help output arguments type: enhancement _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39779> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com