Skip to content

Instantly share code, notes, and snippets.

@joshainglis
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save joshainglis/924397bb9daf5404caa0 to your computer and use it in GitHub Desktop.

Select an option

Save joshainglis/924397bb9daf5404caa0 to your computer and use it in GitHub Desktop.
basic_docopt
def func1(foo):
print("this is func1({})".format(foo))
def func2(foo):
print("this is func2({})".format(foo))
if __name__ == "__main__":
try:
from docopt import docopt
opts = """Usage: my_program.py [-hso FILE] [--quiet | --verbose] [INPUT ...]
-h --help show this
-s --sorted sorted output [default: True]
-o FILE specify output file [default: ./test.txt]
--quiet print less text
--verbose print more text
"""
x = docopt(opts)
print(x)
if not x["--quiet"]:
if x["--sorted"]:
func1(x["-o"])
if x["--verbose"]:
func2(x["-o"])
except ImportError:
print("You need some 'sudo pip install docopt' up in here!")
except Exception as e:
print("Something went horribly wrong.... {}".format(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment