I would like to make one argument be required or not depending on the value of another argument supplied. Here is what I tried
import argparse
argparser = argparse.ArgumentParser()
#instead of hard coding it to always be required like this
#argparser.add_argument('-n', '--name', help='Name', required=True)
#I tried to use a boolean condition in the argparse configuration
argparser.add_argument('-n', '--name', help='Name', required=(not empty))
argparser.add_argument('-e', '--empty', help='Empty execution', action="store_true")
args = argparser.parse_args();
empty = args.empty
name = args.name
this does not work. Of course, I can write my own input validation check as a workaround but I would prefer to do it using the conventional notation, if possible.
Can argparse argument requirement be conditional on other arguments through the canonical API?