Created
November 14, 2017 06:23
-
-
Save stevommmm/a4c30822de2fce68a4704af88585e05b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import sys | |
def argv_absent(arg): | |
'''Check for command line args and run func if not found | |
>>> sys.argv = ['main.py', '--meow'] | |
>>> @argv_absent('--meow') | |
... def meow(): | |
... print("meow") | |
... | |
''' | |
def wrapper(func): | |
if not arg in sys.argv[1:]: | |
return func() | |
return wrapper | |
def argv_required(arg): | |
'''Check for command line args and run func if found | |
>>> sys.argv = ['main.py', '--meow'] | |
>>> @argv_required('--meow') | |
... def meow(): | |
... print("meow") | |
... | |
meow | |
''' | |
def wrapper(func): | |
if arg in sys.argv[1:]: | |
return func() | |
return wrapper | |
@argv_required('--doctest') | |
def meowtime(): | |
import doctest | |
print(doctest.testmod(report=True)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment