This commit is contained in:
BONG-U SON 2023-11-09 17:22:40 +09:00 committed by GitHub
commit d778bb3738
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 7 deletions

View File

@ -4,8 +4,8 @@ from thefuck.types import Command
@pytest.fixture
def pip_unknown_cmd_without_recommend():
return '''ERROR: unknown command "i"'''
def synonym():
return 'remove'
@pytest.fixture
@ -18,6 +18,11 @@ def suggested():
return 'install'
@pytest.fixture
def pip_unknown_cmd_without_recommend(synonym):
return 'ERROR: unknown command "{}"'.format(synonym)
@pytest.fixture
def pip_unknown_cmd(broken, suggested):
return 'ERROR: unknown command "{}" - maybe you meant "{}"'.format(broken, suggested)
@ -25,8 +30,7 @@ def pip_unknown_cmd(broken, suggested):
def test_match(pip_unknown_cmd, pip_unknown_cmd_without_recommend):
assert match(Command('pip instatl', pip_unknown_cmd))
assert not match(Command('pip i',
pip_unknown_cmd_without_recommend))
assert match(Command('pip remove', pip_unknown_cmd_without_recommend))
@pytest.mark.parametrize('script, broken, suggested, new_cmd', [
@ -35,3 +39,11 @@ def test_match(pip_unknown_cmd, pip_unknown_cmd_without_recommend):
def test_get_new_command(script, new_cmd, pip_unknown_cmd):
assert get_new_command(Command(script,
pip_unknown_cmd)) == new_cmd
@pytest.mark.parametrize('script, synonym, new_cmd', [
('pip delete thefuck', 'delete', 'pip uninstall thefuck'),
('pip remove thefuck', 'remove', 'pip uninstall thefuck')
])
def test_get_new_command_without_recommended(script, new_cmd, pip_unknown_cmd_without_recommend):
assert get_new_command(Command(script, pip_unknown_cmd_without_recommend)) == new_cmd

View File

@ -8,12 +8,18 @@ from thefuck.specific.sudo import sudo_support
def match(command):
return ('pip' in command.script and
'unknown command' in command.output and
'maybe you meant' in command.output)
('maybe you meant' in command.output or
'delete' in command.output or
'remove' in command.output))
def get_new_command(command):
broken_cmd = re.findall(r'ERROR: unknown command "([^"]+)"',
command.output)[0]
new_cmd = re.findall(r'maybe you meant "([^"]+)"', command.output)[0]
suggest = re.findall(r'maybe you meant "([^"]+)"', command.output)
suggest = suggest[0] if suggest else None
return replace_argument(command.script, broken_cmd, new_cmd)
if broken_cmd == 'delete' or broken_cmd == 'remove':
suggest = 'uninstall'
return replace_argument(command.script, broken_cmd, suggest)