paul j3 added the comment:
In the attached patch I modified 'add_parser' to take a 'parser' keyword
parameter. If given, it is used as the parser, rather than create a new one.
Thus an existing parser, or one created with a custom ArgumentParser class,
could be used as a subparser.
In
Changes by Mickaël Falck lastmi...@gmail.com:
--
nosy: +Mickaël.Falck
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17204
___
___
Python-bugs-list
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
paul j3 added the comment:
The 'subparsers' object has a _parser_class attribute that is normally set to
the class of the parent parser. In the attached file I create a
class CustomParser(argparse.ArgumentParser)
that makes a parser instance which copies all of the attributes of
Changes by Greg Trahair greg.trah...@gmail.com:
--
nosy: +Greg.Trahair
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17204
___
___
Changes by Greg Trahair greg.trah...@gmail.com:
--
nosy: -Greg.Trahair
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue17204
___
___
New submission from Chris Jerdonek:
Currently, argparser's subparsers.add_parser() method (for adding sub-commands)
takes the following input:
This object has a single method, add_parser(), which takes a command name and
any ArgumentParser constructor arguments, and returns an ArgumentParser