Steven Bethard <[email protected]> added the comment:
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.
----------
resolution: -> wont fix
status: open -> closed
versions: -Python 2.7, Python 3.2, Python 3.3
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue15327>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com