mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
Add composer rule
This commit is contained in:
parent
8376fed459
commit
473f5e6a33
48
tests/rules/test_composer_not_command.py
Normal file
48
tests/rules/test_composer_not_command.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import pytest
|
||||||
|
from thefuck.main import Command
|
||||||
|
from thefuck.rules.composer_not_command import match, get_new_command
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def composer_not_command():
|
||||||
|
return """
|
||||||
|
|
||||||
|
|
||||||
|
[InvalidArgumentException]
|
||||||
|
Command "udpate" is not defined.
|
||||||
|
Did you mean this?
|
||||||
|
update
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def composer_not_command_one_of_this():
|
||||||
|
return """
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[InvalidArgumentException]
|
||||||
|
Command "pdate" is not defined.
|
||||||
|
Did you mean one of these?
|
||||||
|
selfupdate
|
||||||
|
self-update
|
||||||
|
update
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
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 pdate', '', composer_not_command_one_of_this), 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):
|
||||||
|
assert get_new_command(Command('composer udpate', '', composer_not_command), None)\
|
||||||
|
== 'composer update'
|
||||||
|
assert get_new_command(
|
||||||
|
Command('composer pdate', '', composer_not_command_one_of_this), None) == 'composer selfupdate'
|
16
thefuck/rules/composer_not_command.py
Normal file
16
thefuck/rules/composer_not_command.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
def match(command, settings):
|
||||||
|
return ('composer' in command.script
|
||||||
|
and (
|
||||||
|
'did you mean this?' in command.stderr.lower()
|
||||||
|
or 'did you mean one of these?' in command.stderr.lower()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_new_command(command, settings):
|
||||||
|
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)
|
||||||
|
if not new_cmd:
|
||||||
|
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)
|
Loading…
x
Reference in New Issue
Block a user