This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author John.Didion
Recipients John.Didion
Date 2011-03-17.15:51:29
SpamBayes Score 4.915817e-08
Marked as misclassified No
Message-id <1300377092.03.0.159307937388.issue11588@psf.upfronthosting.co.za>
In-reply-to
Content
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))
History
Date User Action Args
2011-03-17 15:51:32John.Didionsetrecipients: + John.Didion
2011-03-17 15:51:32John.Didionsetmessageid: <1300377092.03.0.159307937388.issue11588@psf.upfronthosting.co.za>
2011-03-17 15:51:29John.Didionlinkissue11588 messages
2011-03-17 15:51:29John.Didioncreate