parser = argparse.ArgumentParser()
parser.add_argument("first_arg")
parser.add_argument("--second_arg")
I want to say that second_arg should only be accepted when first_arg takes a certain value , for example "A". How can I do this?
It may be simplest just to do this manually after parsing args:
import sys
args = parser.parse_args()
if args.first_arg != 'A' and args.second_arg: # second_arg 'store_true'
sys.exit("script.py: error: some error message")
Or if second_arg isn't store_true, set second_arg's default to None. Then the conditional is:
if args.first_arg != 'A' and args.second_arg is not None: