Make entry points simpler

This commit is contained in:
Anthony Sottile 2014-03-22 18:11:30 -07:00
parent 6d1a464c4f
commit 04b421978a
8 changed files with 59 additions and 31 deletions

View file

@ -1,6 +1,7 @@
import functools
import os
import sys
class cached_property(object):
@ -35,3 +36,16 @@ def memoize_by_cwd(func):
wrapper._cache = {}
return wrapper
def entry(func):
"""Allows a function that has `argv` as an argument to be used as a
commandline entry. This will make the function callable using either
explicitly passed argv or defaulting to sys.argv[1:]
"""
@functools.wraps(func)
def wrapper(argv=None):
if argv is None:
argv = sys.argv[1:]
return func(argv)
return wrapper