Use decorator library

This commit is contained in:
nvbn
2015-08-27 16:52:26 +03:00
parent 0c283ff2b8
commit ebe53f0d18
5 changed files with 52 additions and 61 deletions
+19 -21
View File
@@ -1,34 +1,32 @@
from functools import wraps
import re
from shlex import split
from decorator import decorator
from ..types import Command
from ..utils import quote, for_app
from ..utils import quote, is_app
def git_support(fn):
@decorator
def git_support(fn, command, settings):
"""Resolves git aliases and supports testing for both git and hub."""
# supports GitHub's `hub` command
# which is recommended to be used with `alias git=hub`
# but at this point, shell aliases have already been resolved
if not is_app(command, 'git', 'hub'):
return False
@for_app('git', 'hub')
@wraps(fn)
def wrapper(command, settings):
# perform git aliases expansion
if 'trace: alias expansion:' in command.stderr:
search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
command.stderr)
alias = search.group(1)
# perform git aliases expansion
if 'trace: alias expansion:' in command.stderr:
search = re.search("trace: alias expansion: ([^ ]*) => ([^\n]*)",
command.stderr)
alias = search.group(1)
# by default git quotes everything, for example:
# 'commit' '--amend'
# which is surprising and does not allow to easily test for
# eg. 'git commit'
expansion = ' '.join(map(quote, split(search.group(2))))
new_script = command.script.replace(alias, expansion)
# by default git quotes everything, for example:
# 'commit' '--amend'
# which is surprising and does not allow to easily test for
# eg. 'git commit'
expansion = ' '.join(map(quote, split(search.group(2))))
new_script = command.script.replace(alias, expansion)
command = Command._replace(command, script=new_script)
command = Command._replace(command, script=new_script)
return fn(command, settings)
return wrapper
return fn(command, settings)