Move get_all_matched_commands over to utils
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import re
|
||||
from thefuck.utils import get_closest, git_support, replace_argument
|
||||
from thefuck.utils import (get_closest, git_support, replace_argument,
|
||||
get_all_matched_commands)
|
||||
|
||||
|
||||
@git_support
|
||||
@@ -8,20 +9,11 @@ def match(command, settings):
|
||||
and 'Did you mean' in command.stderr)
|
||||
|
||||
|
||||
def _get_all_git_matched_commands(stderr):
|
||||
should_yield = False
|
||||
for line in stderr.split('\n'):
|
||||
if 'Did you mean' in line:
|
||||
should_yield = True
|
||||
elif should_yield and line:
|
||||
yield line.strip()
|
||||
|
||||
|
||||
@git_support
|
||||
def get_new_command(command, settings):
|
||||
broken_cmd = re.findall(r"git: '([^']*)' is not a git command",
|
||||
command.stderr)[0]
|
||||
new_cmd = get_closest(broken_cmd,
|
||||
_get_all_git_matched_commands(command.stderr))
|
||||
get_all_matched_commands(command.stderr))
|
||||
return replace_argument(command.script, broken_cmd, new_cmd)
|
||||
|
||||
|
||||
@@ -159,3 +159,12 @@ def replace_argument(script, from_, to):
|
||||
else:
|
||||
return script.replace(
|
||||
u' {} '.format(from_), u' {} '.format(to), 1)
|
||||
|
||||
|
||||
def get_all_matched_commands(stderr, separator='Did you mean'):
|
||||
should_yield = False
|
||||
for line in stderr.split('\n'):
|
||||
if separator in line:
|
||||
should_yield = True
|
||||
elif should_yield and line:
|
||||
yield line.strip()
|
||||
|
||||
Reference in New Issue
Block a user