zenlotus / argparse

Automatically exported from code.google.com/p/argparse
Other
0 stars 0 forks source link

When using subcommands, option in parent parser should be placeable anywhere #54

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by ianbick...@gmail.com on 7 Jan 2010 at 12:07

GoogleCodeExporter commented 9 years ago
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.

Original comment by steven.b...@gmail.com on 7 Jan 2010 at 5:37

GoogleCodeExporter commented 9 years ago

Original comment by steven.b...@gmail.com on 28 Feb 2010 at 10:08