[issue42980] argparse: GNU-style help formatter

paul j3 report at bugs.python.org
Thu Jan 21 16:12:38 EST 2021


paul j3 <ajipanca at gmail.com> added the comment:

The refactoring looks reasonable.

But while we are tweaking:

    def _format_action_invocation(self, action):

I wonder if we also give users more control over how multiple option strings are formatted.  Currently if 

     parser.add_argument('-f', '--foo', help='something')

the help line will be

     -f FOO, --foo FOO     something

with this alternate formatter it would be (I think)

     -f FOO, --foo=FOO     something

But with longer option strings users often want

     -f, --foo FOO         something

or even just

     -f, --foo             something

we can almost get the last with `metavar=''`

     -f , --foo            something

which has a superfluous space before the comma.

I don't recall if there's already a bug/issue for this or not.  Maybe the fix is a subclass with a complete replacement of this _format_action_invocation method.  I'll have do more research (here and on Stackoverflow).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42980>
_______________________________________


More information about the Python-bugs-list mailing list