This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author bethard
Recipients Ingo.Fischer, bethard, ezio.melotti, samwyse, tshepang
Date 2012-07-22.23:53:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1343001220.72.0.583329258326.issue15327@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012-07-22 23:53:40bethardsetrecipients: + bethard, samwyse, ezio.melotti, tshepang, Ingo.Fischer
2012-07-22 23:53:40bethardsetmessageid: <1343001220.72.0.583329258326.issue15327@psf.upfronthosting.co.za>
2012-07-22 23:53:40bethardlinkissue15327 messages
2012-07-22 23:53:40bethardcreate