zenlotus / argparse

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

Allow conflicting argument declarations for subparsers #44

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to have a command line with two subcommands, each of which has the
same option.  This appears to be disallowed in the current version.

Example:

  script cmd1 -v
  script cmd2 -v

Original issue reported on code.google.com by whart222 on 25 Nov 2009 at 8:58

GoogleCodeExporter commented 9 years ago
What did you try that didn't work?

>>> parser = argparse.ArgumentParser()
>>> subparsers = parser.add_subparsers()
>>> cmd1 = subparsers.add_parser('cmd1')
>>> cmd1.add_argument('-v', dest='foo')
>>> cmd2 = subparsers.add_parser('cmd2')
>>> cmd2.add_argument('-v', dest='bar')
>>> parser.parse_args(['cmd1', '-v', 'badger'])
Namespace(foo='badger')
>>> parser.parse_args(['cmd2', '-v', 'badger'])
Namespace(bar='badger')

Original comment by steven.b...@gmail.com on 6 Dec 2009 at 11:44

GoogleCodeExporter commented 9 years ago

Original comment by steven.b...@gmail.com on 23 Jul 2010 at 11:44