Message228950
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 this sample script, a parent parser is used as subparser in 2 different ways - via the parent mechanism, and with this new add_parser parameter.
parent = argparse.ArgumentParser()
parent.add_argument('-f')
parent.add_argument('bar')
parser = argparse.ArgumentParser()
sp = parser.add_subparsers(dest='cmd')
p1 = sp.add_parser('cmd1', add_help=False, parents=[parent])
p2 = sp.add_parser('cmd2', parser=parent)
parent.add_argument('test')
assert p2 is parent
assert p1 is not parent
print(parser.parse_args())
This change passes existing unittests. I don't think there are any backward compatibility issues. |
|
Date |
User |
Action |
Args |
2014-10-10 04:35:04 | paul.j3 | set | recipients:
+ paul.j3, bethard, chris.jerdonek, Mickaël.Falck |
2014-10-10 04:35:04 | paul.j3 | set | messageid: <1412915704.69.0.77869363943.issue17204@psf.upfronthosting.co.za> |
2014-10-10 04:35:04 | paul.j3 | link | issue17204 messages |
2014-10-10 04:35:04 | paul.j3 | create | |
|