import argparse,os
data_func=["upload","download"]
req_func=["getfunc","postfunc"]
def func1():
print("this func1")
def func2():
print("this is func2")
parser=argparse.ArgumentParser()
parser.add_argument('-j',"--jobid",required=False,type=str,help="this is jobid")
parser.add_argument("-host",required=False,type=str,help="this is role of host part ")
parser.add_argument("-f","--function",type=str,choices=(data_func+req_func))
parser.add_argument("-r","--role",type=str,help="role of server")
parser.add_argument("--nargs",nargs='+',help="type need list test ")
parser.add_argument("-muti",action="append",help="muti append")
parser.add_argument("-c","--config",required=False,type=str,help="config of run time ")
args=parser.parse_args()
print(args.__dict__)
print(os.path.abspath('cases/Homo.py'))
D:\workspace\AutoFate\src\cases>python argparseutils.py -f download -j 20190001 -r guest -host host1 --a aaa --a bbb --a 9999
{'jobid': '20190001', 'host': 'host1', 'function': 'download', 'role': 'guest', 'nargs': None, 'a': ['aaa', 'bbb', '9999']}
D:\workspace\AutoFate\src\cases>python argparseutils.py -f download -j 20190001 -r guest -host host1 -muti aa -muti bb -muti 888
{'jobid': '20190001', 'host': 'host1', 'function': 'download', 'role': 'guest', 'nargs': None, 'muti': ['aa', 'bb', '888']}
D:\workspace\AutoFate\src\cases>python argparseutils.py -f download -j 20190001 -r guest -host host1 --nargs 999 aa bbb
{'jobid': '20190001', 'host': 'host1', 'function': 'download', 'role': 'guest', 'nargs': ['999', 'aa', 'bbb'], 'muti': None}
D:\workspace\AutoFate\src\cases>python argparseutils.py -f download -c exampels/testconfig.json
{'jobid': None, 'host': None, 'function': 'download', 'role': None, 'nargs': None, 'muti': None, 'config': 'exampels/testconfig.json'}
exampels/testconfig.json
D:\workspace\AutoFate\src\cases>python argparseutils.py -f download -c exampels/testconfig.json
{'jobid': None, 'host': None, 'function': 'download', 'role': None, 'nargs': None, 'muti': None, 'config': 'exampels/testconfig.json'}
D:\workspace\AutoFate\src\cases\cases\Homo.py