[docs] [issue9694] argparse required arguments displayed under "optional arguments"

paul j3 report at bugs.python.org
Thu Feb 13 09:34:38 CET 2014


paul j3 added the comment:

The attached file shows how the default argument groups could be redefined, using 'required' as the criteria.

I've implemented it as a method that is added to a subclass of ArgumentParser.  This method is invoked after arguments are defined, prior to generating the help.

The help looks something like this:

    usage: alt_grouping.py [-h] [-f FOO] -g GOO pos [baz]

    required:
      pos                required positional
      -g GOO, --goo GOO  required optional

    optional:
      -h, --help         show this help message and exit
      -f FOO, --foo FOO  optional
      baz                optional positional

I was thinking of implementing this as a formatter subclass, but given the way the help is assembled, invoking this method from the parser is simpler.

----------
Added file: http://bugs.python.org/file34065/alt_grouping.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9694>
_______________________________________


More information about the docs mailing list