Skip to content

Instantly share code, notes, and snippets.

@namoopsoo
Created January 12, 2019 22:49
Show Gist options
  • Save namoopsoo/154c97ef4fa0d36a4daffeeb0d1affd5 to your computer and use it in GitHub Desktop.
Save namoopsoo/154c97ef4fa0d36a4daffeeb0d1affd5 to your computer and use it in GitHub Desktop.
python argparse boilerplate
import argparse
def bake_options():
return [
[['--verbose', '-v'],
{'action': 'store_true',
'help': 'pass to to be verbose with commands'},
],
[['--dry-run', '-D'],
{'action': 'store_true',
'help': 'Dry run. Just print the command. '},]
]
##
# help='',
# default='',
# required='',
# choices='',
# action='',
# type='',
def do():
parser = argparse.ArgumentParser()
[parser.add_argument(*x[0], **x[1])
for x in bake_options()]
# Collect args from user.
args = parser.parse_args()
print vars(args)
do()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment