I am using Argparse module in python for developing a Command Line Tool. Here's the parser code:
from argparse import ArgumentParser
def arguments():
parser = ArgumentParser()
parser.add_argument('-c' , '--comms' , action = "store" , default = None , type = str , dest = "command",
help = 'Choosing a Command')
parser.add_argument( '-s' , '--search' , action = 'store' , default = None , type = str , dest = 'search_path' ,
help = 'Search for a command' )
parser.add_argument( '-f' , '--config' , action = 'store_true' ,
help = 'Show the present configuration')
parser.add_argument('--flush_details' , action = "store_false" ,
help = "Flushes the current commands buffer")
return parser.parse_args()
def main():
parser_results = arguments()
#More code comes here to analyze the results
However, when I run the code python foo.py --help, it never runs the script post parsing the arguments. Is there anything I can do to stop the behaviour. I want to analyse the parser results even if it is just asked for --help switch.
Would like to know what can I do to continue the script even after --help has been used
--helpis meant to print the help and exit, as expected by any well-behaved command line tool. So, nothing should run afterwards, and there is nothing to analyze. What is it that you are really trying to do?-help, what is there to parse? It is pretty universal that asking for the help prints the help message and terminates the program. Can you be more specific on your expected behavior? Are you expecting other arguments to be passed along with the-helpargument? Please give some more run examples with their expected output.