Add information about writting yourself rules, revert no_command changes
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
from functools import wraps
|
||||
import os
|
||||
|
||||
|
||||
def which(program):
|
||||
"""Returns `program` path or `None`."""
|
||||
|
||||
def is_exe(fpath):
|
||||
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
||||
|
||||
@@ -17,3 +20,24 @@ def which(program):
|
||||
return exe_file
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def wrap_settings(params):
|
||||
"""Adds default values to settings if it not presented.
|
||||
|
||||
Usage:
|
||||
|
||||
@wrap_settings({'apt': '/usr/bin/apt'})
|
||||
def match(command, settings):
|
||||
print(settings.apt)
|
||||
|
||||
"""
|
||||
def decorator(fn):
|
||||
@wraps(fn)
|
||||
def wrapper(command, settings):
|
||||
for key, val in params.items():
|
||||
if not hasattr(settings, key):
|
||||
setattr(settings, key, val)
|
||||
return fn(command, settings)
|
||||
return wrapper
|
||||
return decorator
|
||||
|
||||
Reference in New Issue
Block a user