New issue 54 by ianbicking: When using subcommands, option in parent parser
should be placeable anywhere
http://code.google.com/p/argparse/issues/detail?id=54
I have a command with a bunch of subcommands. In the parent parser I added
a verbose option. I can do:
mycommand --verbose subcommand --something
But I expect to also be able to do this:
mycommand subcommand --verbose --something
But... I can't.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
That's intentional because it's possible you might want those two --verbose
flags to
mean different things. If you want them to mean the same things, I'd
suggest using a
parent parser:
verbose_parser = argparse.ArgumentParser(add_help=False)
verbose_parser.add_argument('--verbose', action='store_true')
parser = argparse.ArgumentParser(parents=[verbose_parser])
subparsers = parser.add_subparsers()
foo_parser = subparsers.add_parser('foo', parents=[verbose_parser])
That should allow the same --verbose flag to be specified in either parser.
Comment #2 on issue 54 by steven.bethard: When using subcommands, option in
parent parser should be placeable anywhere
http://code.google.com/p/argparse/issues/detail?id=54
(No comment was entered for this change.)