Skip to content

Instantly share code, notes, and snippets.

@stevommmm
Created November 14, 2017 06:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevommmm/a4c30822de2fce68a4704af88585e05b to your computer and use it in GitHub Desktop.
Save stevommmm/a4c30822de2fce68a4704af88585e05b to your computer and use it in GitHub Desktop.
#!/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