Last active
August 29, 2015 14:09
-
-
Save joshainglis/924397bb9daf5404caa0 to your computer and use it in GitHub Desktop.
basic_docopt
This file contains hidden or 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
| 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