Created
January 12, 2019 22:49
-
-
Save namoopsoo/154c97ef4fa0d36a4daffeeb0d1affd5 to your computer and use it in GitHub Desktop.
python argparse boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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