define complex mutual exclusive arguments with argparse

167 views Asked by At

I know there is ArgumentParser.add_mutually_exclusive_group() which lets me choose between mutually exclusive options o1, o2, .. Can I also define 'complex' argument groups which are mutually exclusive?

e.g. imagine I had to provide either username and password or a filename with credentials

my_program connect example.com --username me --password you

OR

my_program connect example.com --credential-file this/file.json

Of course I could define an option --credentials which would take both username and password so add_mutually_exclusive_group would be enough but I'm curious whether groups of arguments can be mutually exclusive, too.

0

There are 0 answers