mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Make entry points simpler
This commit is contained in:
parent
6d1a464c4f
commit
04b421978a
8 changed files with 59 additions and 31 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue