This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author brian.gallagher
Recipients brian.gallagher
Date 2020-02-27.23:40:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582846807.44.0.751374358876.issue39779@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-02-27 23:40:07brian.gallaghersetrecipients: + brian.gallagher
2020-02-27 23:40:07brian.gallaghersetmessageid: <1582846807.44.0.751374358876.issue39779@roundup.psfhosted.org>
2020-02-27 23:40:07brian.gallagherlinkissue39779 messages
2020-02-27 23:40:07brian.gallaghercreate