mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 12:06:04 +00:00
Add a support for pip unknown commands
This commit is contained in:
parent
0272e8a801
commit
af2bfe7c58
24
tests/rules/test_pip_unknown_command.py
Normal file
24
tests/rules/test_pip_unknown_command.py
Normal file
@ -0,0 +1,24 @@
|
||||
import pytest
|
||||
from thefuck.types import Command
|
||||
from thefuck.rules.pip_unknown_command import match, get_new_command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pip_unknown_cmd():
|
||||
return '''ERROR: unknown command "instatl" - maybe you meant "install"'''
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def pip_unknown_cmd_without_recommend():
|
||||
return '''ERROR: unknown command "i"'''
|
||||
|
||||
|
||||
def test_match(pip_unknown_cmd, pip_unknown_cmd_without_recommend):
|
||||
assert match(Command('pip instatl', '', pip_unknown_cmd), None)
|
||||
assert not match(Command('pip i', '', pip_unknown_cmd_without_recommend),
|
||||
None)
|
||||
|
||||
|
||||
def test_get_new_command(pip_unknown_cmd):
|
||||
assert get_new_command(Command('pip instatl', '', pip_unknown_cmd), None)\
|
||||
== 'pip install'
|
15
thefuck/rules/pip_unknown_command.py
Normal file
15
thefuck/rules/pip_unknown_command.py
Normal file
@ -0,0 +1,15 @@
|
||||
import re
|
||||
|
||||
|
||||
def match(command, settings):
|
||||
return ('pip' in command.script and
|
||||
'unknown command' in command.stderr and
|
||||
'maybe you meant' in command.stderr)
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
broken_cmd = re.findall(r'ERROR: unknown command \"([a-z]+)\"',
|
||||
command.stderr)[0]
|
||||
new_cmd = re.findall(r'maybe you meant \"([a-z]+)\"', command.stderr)[0]
|
||||
|
||||
return command.script.replace(broken_cmd, new_cmd, 1)
|
Loading…
x
Reference in New Issue
Block a user