classification
Title: argparse redundant help string
Type: enhancement Stage:
Components: Library (Lib) Versions:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jwilk, paul.j3, stefan
Priority: normal Keywords:

Created on 2018-04-29 19:38 by stefan, last changed 2018-05-05 02:34 by paul.j3.

Messages (5)
msg315917 - (view) Author: Stefan Seefeld (stefan) * (Python committer) Date: 2018-04-29 19:38
I'm using Python's `argparse` module to define optional arguments.
I'm calling the `argparse.add_argument` method to add both short and long arguments, but I notice that the generated help message lists some information twice. For example:
```
argparse.add_argument('-s', '--service',...)
```
will generate

```
-s SERVICE, --service SERVICE
```
and when I add a `choices` argument, even the choices list is repeated. I think it would be more useful to suppress the repetition to produce output such as
```
-s|--service SERVICE ...
```
instead with both the meta var as well as choices etc. printed only once.
msg316180 - (view) Author: Jakub Wilk (jwilk) Date: 2018-05-04 16:58
GNU programs seem to use this format:

   $ ls --help | grep ',.*=[A-Z]'
     -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
     -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
     -w, --width=COLS           set output width to COLS.  0 means no limit

The argparse format is more accurate, but also less practical, especially for long variable names.
msg316188 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2018-05-05 02:11
This is normal behavior for argparse.

People have asked before for a more compact display.  I remember suggesting changes to the HelpFormatter subclass on Stackoverflow questions, and there's probably one or more bug/issues addressing the same issue.
msg316190 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2018-05-05 02:29
https://bugs.python.org/issue29626
Issue with spacing in argparse module while using help

This deals with a extra space that is produced when a blank metavar is used to produce a more compact help line

   -s , --service   help text

My answers have links to relevant SO questions.
msg316191 - (view) Author: paul j3 (paul.j3) * (Python triager) Date: 2018-05-05 02:34
Also

https://bugs.python.org/issue27303
[argparse] Unify options in help output
History
Date User Action Args
2018-05-05 02:34:18paul.j3setmessages: + msg316191
2018-05-05 02:29:57paul.j3setmessages: + msg316190
2018-05-05 02:11:49paul.j3setnosy: + paul.j3
messages: + msg316188
2018-05-04 16:58:30jwilksetmessages: + msg316180
2018-05-04 16:27:57jwilksetnosy: + jwilk
2018-04-29 19:38:21stefancreate