I am trying to parse conditional command line arguments.
Here is my code
import argparse
def parseArguments():
parser = argparse.ArgumentParser(description="Parses the command line arguments")
parser.add_argument('-launchTest', dest='launchTest', action='store_true', help='provide this to run triage process of test suites')
parser.add_argument('-getStatus', dest='getStatus', action='store_true', help='provide this to run triage process of test suites')
parser.add_argument('-configFile', dest='configFile', required=True, help='provide json config data')
parser.add_argument('-user', dest='user', required=True, action='store', help='provide user name for launching tests on GVS')
parser.add_argument('-date', dest='date' , help='provide date or CL to run tests, date format: MM_DD_YYYY')
parser.add_argument('-cl', dest='cl', help='provide either date or cl to run the tests')
parser.add_argument('-outPutDir', dest='outPutDir', default='/compune-nightly/nightly/{}/GVS-Tegra/', help='provide output directory path to store results')
subparser = parser.add_subparsers(help='sub-command help')
parser_a = subparser.add_parser('testName', help='this to run specific test with testName and test details must be present in argumentConfig.json provide gpu and boardName with this')
parser_a.add_argument('-gpu', action='store', help='provide this to run specific test with testName, testType and test details must be present in argumentConfig.json')
parser_a.add_argument('-boardName', action='store', help='provide this to run specific test with testName, testType, gpu and test details must be present in argumentConfig.json')
arguments = parser.parse_args()
return arguments
def main():
parseArguments()
main()
From this code, I want to add option in parser like if testName is given in command then it is compulasary to provide cpu and boradname.
But When I am trying to run this code it gives Error: parser.py: error: too few arguments
python parser.py -configFile=abcd -user=amanj -testName=xyz -gpu=123 -boardName=123
usage: parser.py [-h] [-launchTest] [-getStatus] -configFile CONFIGFILE -user
USER [-date DATE] [-cl CL] [-outPutDir OUTPUTDIR]
{testName} ... parser.py: error: too few arguments