[issue17204] argparser's subparsers.add_parser() should accept an ArgumentParser

paul j3 report at bugs.python.org
Mon Nov 25 18:41:02 CET 2013


paul j3 added the comment:

http://stackoverflow.com/a/20167038/901925
is an example of using `_parser_class` to produce different behavior in the subparsers.

    parser = ArgumentParser()
    parser.add_argument('foo')
    sp = parser.add_subparsers(dest='cmd')
    sp._parser_class = SubParser # use different parser class for subparsers
    spp1 = sp.add_parser('cmd1')
    spp1.add_argument('-x')
    spp1.add_argument('bar')
    spp1.add_argument('vars',nargs='*')

In this case the SubParser class implements a `parse_intermixed_known_args` method that handles that `nargs='*'` argument.

http://bugs.python.org/issue14191

It shouldn't be hard to add `parser_class` as a documented optional argument to `add_subparsers`.

----------

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


More information about the Python-bugs-list mailing list