If I call the script below with these options:
--user u1 --password p1 --foo f1 --user u2 --user u3 --password p3
Then it will print:
Namespace(foo=['bar', 'f1'], password=['p1', 'p3'], user=['u1', 'u2', 'u3'])
Question: Is there any way for me to set up a dependency between user and password, so it throws an error, because password for user u2 is not specified?
Less relevant question: How do I specify a default foo value for all users? With the given input I would like foo to equal ['f1','bar','bar'].
A solution for my main question would be to check that the lists user and password have the same length, but it's not quite what I'm looking for.
Here is the script:
import argparse
parser = argparse.ArgumentParser()
group = parser.add_argument_group('authentication')
group.add_argument('--user', action='append', required=True)
group.add_argument('--password', action='append', required=True)
group.add_argument('--foo', action='append', default=['bar'])
print(parser.parse_args())