mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 12:28:41 +00:00
Move get_all_matched_commands over to utils
This commit is contained in:
parent
742200a500
commit
4e854a575e
@ -1,7 +1,8 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
from thefuck.utils import git_support, sudo_support, wrap_settings,\
|
from thefuck.utils import git_support, sudo_support, wrap_settings,\
|
||||||
memoize, get_closest, get_all_executables, replace_argument
|
memoize, get_closest, get_all_executables, replace_argument, \
|
||||||
|
get_all_matched_commands
|
||||||
from thefuck.types import Settings
|
from thefuck.types import Settings
|
||||||
from tests.utils import Command
|
from tests.utils import Command
|
||||||
|
|
||||||
@ -99,3 +100,32 @@ def test_get_all_callables():
|
|||||||
(('git brnch', 'brnch', 'branch'), 'git branch')])
|
(('git brnch', 'brnch', 'branch'), 'git branch')])
|
||||||
def test_replace_argument(args, result):
|
def test_replace_argument(args, result):
|
||||||
assert replace_argument(*args) == result
|
assert replace_argument(*args) == result
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('stderr, result', [
|
||||||
|
(("git: 'cone' is not a git command. See 'git --help'.\n"
|
||||||
|
'\n'
|
||||||
|
'Did you mean one of these?\n'
|
||||||
|
'\tclone'), ['clone']),
|
||||||
|
(("git: 're' is not a git command. See 'git --help'.\n"
|
||||||
|
'\n'
|
||||||
|
'Did you mean one of these?\n'
|
||||||
|
'\trebase\n'
|
||||||
|
'\treset\n'
|
||||||
|
'\tgrep\n'
|
||||||
|
'\trm'), ['rebase', 'reset', 'grep', 'rm']),
|
||||||
|
(('tsuru: "target" is not a tsuru command. See "tsuru help".\n'
|
||||||
|
'\n'
|
||||||
|
'Did you mean one of these?\n'
|
||||||
|
'\tservice-add\n'
|
||||||
|
'\tservice-bind\n'
|
||||||
|
'\tservice-doc\n'
|
||||||
|
'\tservice-info\n'
|
||||||
|
'\tservice-list\n'
|
||||||
|
'\tservice-remove\n'
|
||||||
|
'\tservice-status\n'
|
||||||
|
'\tservice-unbind'), ['service-add', 'service-bind', 'service-doc',
|
||||||
|
'service-info', 'service-list', 'service-remove',
|
||||||
|
'service-status', 'service-unbind'])])
|
||||||
|
def test_get_all_matched_commands(stderr, result):
|
||||||
|
assert list(get_all_matched_commands(stderr)) == result
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import re
|
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
|
@git_support
|
||||||
@ -8,20 +9,11 @@ def match(command, settings):
|
|||||||
and 'Did you mean' in command.stderr)
|
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
|
@git_support
|
||||||
def get_new_command(command, settings):
|
def get_new_command(command, settings):
|
||||||
broken_cmd = re.findall(r"git: '([^']*)' is not a git command",
|
broken_cmd = re.findall(r"git: '([^']*)' is not a git command",
|
||||||
command.stderr)[0]
|
command.stderr)[0]
|
||||||
new_cmd = get_closest(broken_cmd,
|
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)
|
return replace_argument(command.script, broken_cmd, new_cmd)
|
||||||
|
|
||||||
|
@ -159,3 +159,12 @@ def replace_argument(script, from_, to):
|
|||||||
else:
|
else:
|
||||||
return script.replace(
|
return script.replace(
|
||||||
u' {} '.format(from_), u' {} '.format(to), 1)
|
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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user