1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-06 02:41:10 +01:00
This commit is contained in:
nvbn 2015-04-23 21:47:46 +02:00
parent 0235c0654d
commit 1f96faef2c
2 changed files with 9 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import pytest import pytest
from thefuck.main import Command from thefuck.types import Command
from thefuck.rules.composer_not_command import match, get_new_command from thefuck.rules.composer_not_command import match, get_new_command
@ -34,15 +34,15 @@ def composer_not_command_one_of_this():
""" """
def test_match(composer_not_command, composer_not_command_one_of_this): def test_match(composer_not_command, composer_not_command_one_of_this):
assert match(Command('composer udpate', '', composer_not_command), None) assert match(Command('composer udpate', '', composer_not_command), None)
assert match(Command('composer pdate', '', composer_not_command_one_of_this), None) assert match(Command('composer pdate', '', composer_not_command_one_of_this), None)
assert not match(Command('ls update', '', composer_not_command), None) assert not match(Command('ls update', '', composer_not_command), None)
#assert not match(Command('composer update', '', composer_command), None)
def test_get_new_command(composer_not_command, composer_not_command_one_of_this): def test_get_new_command(composer_not_command, composer_not_command_one_of_this):
assert get_new_command(Command('composer udpate', '', composer_not_command), None)\ assert get_new_command(Command('composer udpate', '', composer_not_command), None) \
== 'composer update' == 'composer update'
assert get_new_command( assert get_new_command(
Command('composer pdate', '', composer_not_command_one_of_this), None) == 'composer selfupdate' Command('composer pdate', '', composer_not_command_one_of_this), None) == 'composer selfupdate'

View File

@ -1,16 +1,15 @@
import re import re
def match(command, settings): def match(command, settings):
return ('composer' in command.script return ('composer' in command.script
and ( and ('did you mean this?' in command.stderr.lower()
'did you mean this?' in command.stderr.lower() or 'did you mean one of these?' in command.stderr.lower()))
or 'did you mean one of these?' in command.stderr.lower()
)
)
def get_new_command(command, settings): def get_new_command(command, settings):
broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.stderr)[0] broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.stderr)[0]
new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.stderr) new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.stderr)
if not new_cmd: if not new_cmd:
new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)', command.stderr) new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)', command.stderr)
return command.script.replace(broken_cmd, new_cmd[0].strip(), 1) return command.script.replace(broken_cmd, new_cmd[0].strip(), 1)