Given:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--foo')
parser.add_argument('--bar')
print(parser.parse_args('--foo 1'.split()))
How do I
- make at least one of "foo, bar" mandatory:
--foo x,--bar yand--foo x --bar yare fine - make at most one of "foo, bar" mandatory:
--foo xor--bar yare fine,--foo x --bar yis not
I think you are searching for something like mutual exclusion (at least for the second part of your question).
This way, only
--fooor--barwill be accepted, not both.BTW, just found another question referring to the same kind of issue.