I am new on Argparse module. I have almost finished my script but there is something I cannot find a way to do it.
Here is the script:
import argparse
def function1(a, b, c):
#mystaff
def function2(e, f):
#mystaff
def function3(g):
#mystaff
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='blahblah')
parser.add_argument('-a','--a', help='blahblah', required=False, default="defaultvalue")
parser.add_argument('-b','--b', help='blahblah', required=False)
.......
args = parser.parse_args()
function1(args.a,args.b,args.c)
I want to call the script from command prompt. Now, I can use this for example to call the function1
:
python myscript.py -a <var>
What I want is:
python myscript.py -a <var>
: call the function1 as it is now
python myscript.py function2 -c <var>
: call the function2 only
python myscript.py function3 -g <var>
: call the function3 only
So, if I don't specify the function, function1 is the default, otherwise I have to pass the function name from the command prompt too. Any ideas?