def action(action_name=None, keep_comments=False, escape=True):
def decorator(func):
action = action_name or func.__name__.replace('_', '-')
def function_wrapper(*args, **kw):
if not keep_comments:
args = [i for i in args if not i.startswith('#')]
if escape:
args = [shlex.quote(i) for i in args]
res = func(*args, **kw)
# allow actions to yield each line
if not isinstance(res, str) and res is not None:
res = '\n'.join(res)
return res
state['actions'][action] = function_wrapper
return function_wrapper
return decorator
评论列表
文章目录