Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct "pip delete|remove" -> "pip uninstall" #1414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions tests/rules/test_pip_unknown_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@


@pytest.fixture
def pip_unknown_cmd_without_recommend():
return '''ERROR: unknown command "i"'''
def synonym():
return 'remove'


@pytest.fixture
Expand All @@ -18,15 +18,19 @@ 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)


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', [
Expand All @@ -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
12 changes: 9 additions & 3 deletions thefuck/rules/pip_unknown_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
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)