Message166184
I don't think there's any easy way for argparse to automatically do what you want. However, there's a simple workaround - just use the dest= argument and specify two different destinations:
>>> parser = argparse.ArgumentParser()
>>> parser.add_argument('--verbose', action='store_true', dest='verbose_main')
>>> subparsers = parser.add_subparsers(help='command', dest='command')
>>> cmd1_parser = subparsers.add_parser('command')
>>> cmd1_parser.add_argument('--verbose', action='store_true', dest='verbose_sub')
>>> parser.parse_args(['command', '--verbose'])
Namespace(command='command', verbose_main=False, verbose_sub=True)
>>> parser.parse_args(['--verbose', 'command'])
Namespace(command='command', verbose_main=True, verbose_sub=False)
Closing as a wontfix, but feel free to reopen if you want to provide a patch for something. |
|
Date |
User |
Action |
Args |
2012-07-22 23:53:40 | bethard | set | recipients:
+ bethard, samwyse, ezio.melotti, tshepang, Ingo.Fischer |
2012-07-22 23:53:40 | bethard | set | messageid: <1343001220.72.0.583329258326.issue15327@psf.upfronthosting.co.za> |
2012-07-22 23:53:40 | bethard | link | issue15327 messages |
2012-07-22 23:53:40 | bethard | create | |
|