Closed GoogleCodeExporter closed 8 years ago
I think that's basically right - the only thing that really needs to be done is
to
add the arguments to the _MutuallyExclusiveGroup __init__ and then pass them on
the
super() call.
As to why no one else has asked for this, I don't have a good answer. ;-)
I'll get this incorporated into the next version of argparse. If you have the
time to
write a test or two for this behavior and then send me a patch with the change
and
the tests, that would be great.
Original comment by steven.b...@gmail.com
on 4 Feb 2010 at 5:48
So, I worked on this for a while today, and while I still believe it's
possible, the
suggested change above doesn't work because it breaks the formatting of regular
groups. If you have a patch that adds this functionality and doesn't break the
current tests, I'd be happy to look at it.
Original comment by steven.b...@gmail.com
on 1 Mar 2010 at 7:11
I'm going to close this as WontFix. There's a pretty straightforward
alternative which is to create a group with a title and description, and add
the mutually exclusive group to that. If you'd like to implement a patch for
the simplified version, please open a new ticket with a patch at
bugs.python.org.
Original comment by steven.b...@gmail.com
on 23 Jul 2010 at 12:50
Workaround described in comment #3 doesn't seem to support "required=True"
parameter. For example:
=======================================================================
$ cat t.py
#!/build/toolchain/lin32/python-2.6.1/bin/python
import argparse
parser = argparse.ArgumentParser('test')
group = parser.add_argument_group('Verbosities', 'Controls level of output')
mutex_group = group.add_mutually_exclusive_group(required=True)
mutex_group.add_argument('-q', action='store_true', default=False,
help='Quiet mode')
mutex_group.add_argument('-v', action='store_true', default=False,
help='Verbose mode')
args = parser.parse_args()
print 'q=%s v=%s' % (args.q, args.v)
$ ./t.py
q=False v=False
=======================================================================
I would have expected either -q or -v to have been required, i.e. this behavior:
=======================================================================
$ ./t.py
usage: test [-h] (-q | -v)
test: error: one of the arguments -q -v is required
=======================================================================
Original comment by kew...@gmail.com
on 23 Jul 2010 at 2:20
Well that looks like a bug. Could you please file a bug on bugs.python.org?
This bug tracker is no longer in use. Thanks!
Original comment by steven.b...@gmail.com
on 23 Jul 2010 at 2:38
Hi Steven,
I am sorry to comment on something closed for so long.
http://bugs.python.org/issue10680 is resolved in python 2.7
Can we please port the fix here so it is available for python <= 2.6?
Thank you.
Original comment by damien.n...@gmail.com
on 3 Apr 2013 at 5:18
Original issue reported on code.google.com by
chphilli
on 31 Jan 2010 at 10:22