The simplest solution is to make '-a'
a required=True
argument, and leave the others with default not-required. Then after parsing perform the tests on a args.a
and the other values (I assume you can write that kind of Python logic).
You can raise your own errors, or you can use a parser.error("I don't like your input")
call.
You many need to write a custom usage
line. What would be a meaningful usage, given these requirements?
There is a mutually exclusive argument group
method, but it does not use specific values, just the presence or not of arguments.
You could also incorporate the tests in custom Action classes. But usually that's more complicated than performing the tests after parsing (since argparse handles arguments that occur in any order).
Another possibility to convert the -a
argument into a subparser. That allows you to define one set of arguments for one 'parser' value, and another set for another value. I think the argparse documentation is clear enough on that.