Skip to content

Instantly share code, notes, and snippets.

@xuru
Created November 12, 2012 22:52
Show Gist options
  • Select an option

  • Save xuru/4062602 to your computer and use it in GitHub Desktop.

Select an option

Save xuru/4062602 to your computer and use it in GitHub Desktop.
argparse for the impatient
import argparse
parser = argparse.ArgumentParser(description='Spawn an army of test-robot '
'agents for the purpose of automated testing')
parser.add_argument('-c', '--create-test', action='store_true',
help='Create a new test...')
parser.add_argument('-t', '--test-case', dest='testcase',
default="robot_script.json" help='Test case file name (i.e. robot_script.json)')
# the default action here is to store False in opts.dumptest, and is not
# required
parser.add_argument('-d', '--dump-test', action="store_false", required=False,
help='Optional argument to dump the test at the end')
# you don't need a short option either, like...
parser.add_argument('--clean_first', action='store_true',
help='When given, the script will delete each database before '
'populating it.')
opts = parser.parse_args()
print opts
if opts.dump_test:
# this defaults to False, so the user specifically set -d
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment