I'm using argparse to parse command line arguments. However at this time, I have an unusual request: I want to suppress the error message. For example:
# !/usr/bin/env python
try:
parser = argparse.ArgumentParser(description='Parse')
parser.add_argument('url', metavar='URL', type=str, nargs='+',
help='Specify URL')
except:
print("Invalid arguments or number of arguments")
exit(2)
so I only expect that to print "Invalid arguments or number of arguments" and nothing else. However, then I execute the code for example:
./foo --BOGUS
I'm getting the full usage message:
usage: foo [-h]
foo: error: too few arguments
foo: Invalid arguments or number of arguments
How can I achieve that?