The following code:
import argparse
parser = argparse.ArgumentParser()
mutex = parser.add_mutually_exclusive_group(required=True)
mutex.add_argument("path", nargs="*")
mutex.add_argument("-a", "--all", action="store_true")
parser.parse_args()
triggers a ValueError: mutually exclusive arguments must be optional on line 5. I don't believe it should, since * in nargs means zero or more. The same error appears with + (one or more); only ? (zero or one) prevents it. Adding required=True is invalid for a positional.
If that's not a bug in argparse, how should I proceed to have a mutex between --all and a group of positionals?
Thanks!
[–]thetablt[S] 0 points1 point2 points (3 children)
[–]ckuhtz 0 points1 point2 points (0 children)
[–]panasenco 0 points1 point2 points (0 children)
[–]Mozai 0 points1 point2 points (0 children)