i have de folowing situation, as you can see there are 3 required arguments
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-u','--url', required=True)
parser.add_argument('-l','--lang', required=True)
parser.add_argument('-c','--code', required=True)
args = parser.parse_args()
Now I want to add the argument --list-lang
, this argument shows a list of available languages
The thing is that I want to copy the behaviour of the --help argument, if the program is executed only with the --list-lang argument it has to show the list of languages, the problem is that the rest of the arguments are needed and when I execute the program in the following way it stops and says that there are missing arguments.
python3 file.py --list-lang
I have tried the following code:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--list-lang', action='store_true')
parser.add_argument('-u','--url', required=True)
parser.add_argument('-l','--lang', required=True)
parser.add_argument('-c','--code', required=True)
args = parser.parse_args()
if args.list_lang:
show_list_lang()
Is there a way to do this, or do I just remove rel required from the arguments and check them by hand?