New submission from John Didion <[email protected]>:
Just as some options are mutually exclusive, there are others that are
"necessarily inclusive," i.e. all or nothing. I propose the addition of
ArgumentParser.add_necessarily_inclusive_group(required=True).
This also means that argparse will need to support nested groups. For example,
if I want to set up options such that the user has to provide an output file OR
(an output directory AND (an output file pattern OR an output file extension)):
output_group = parser.add_mutually_exclusive_group(required=True)
output_group.add_argument("-o", "--outfile")
outdir_group = output_group.add_necessarily_inclusive_group()
outdir_group.add_argument("-O", "--outdir")
outfile_group = outdir_group.add_mutually_exclusive_group(required=True)
outfile_group.add_argument("-p", "--outpattern")
outfile_group.add_argument("-s", "--outsuffix")
The usage should then look like:
(-o FILE | (-O DIR & (-p PATTERN | -s SUFFIX))
----------
messages: 131262
nosy: John.Didion
priority: normal
severity: normal
status: open
title: Add "necessarily inclusive" groups to argparse
type: feature request
versions: Python 2.7
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue11588>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com