Currently, argparse of my code gives the following:
usage: ir.py [-h] [-q | --json | -d ]
Some text
optional arguments:
-h, --help show this help message and exit
-q gene query terms (e.g. mcpip1)
--json output in JSON format, use only with -q
-d , --file_to_index file to index
What I want to do is the following:
-q should be mutually excluded from -d- and
--jsonshould only go with-q
How will this go? This is my argparse code:
parser = argparse.ArgumentParser(description='''Some text''')
group = parser.add_mutually_exclusive_group()
group.add_argument("-q",help="gene query terms (e.g. mcpip1)",metavar="",type=str)
group.add_argument("--json", help="output in JSON format, use only with -q", action="store_true")
group.add_argument("-d","--file_to_index", help="file to index",metavar="",type=str)
args = parser.parse_args()
He currently rejects -qwith --json:
python ir.py --json -q mcpip1
usage: ir.py [-h] [-q | --json | -d ]
ir.py: error: argument -q: not allowed with argument --json
source
share