1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-18 20:11:17 +00:00

#1123: Update composer_not_command rule (#1135)

Fix #1123
This commit is contained in:
Divy Jain 2021-07-01 02:40:06 +05:30 committed by GitHub
parent 9201ce79cf
commit 54253027e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View File

@ -39,18 +39,28 @@ def composer_not_command_one_of_this():
) )
def test_match(composer_not_command, composer_not_command_one_of_this): @pytest.fixture
def composer_require_instead_of_install():
return 'Invalid argument package. Use "composer require package" instead to add packages to your composer.json.'
def test_match(composer_not_command, composer_not_command_one_of_this, composer_require_instead_of_install):
assert match(Command('composer udpate', assert match(Command('composer udpate',
composer_not_command)) composer_not_command))
assert match(Command('composer pdate', assert match(Command('composer pdate',
composer_not_command_one_of_this)) composer_not_command_one_of_this))
assert match(Command('composer install package',
composer_require_instead_of_install))
assert not match(Command('ls update', composer_not_command)) assert not match(Command('ls update', composer_not_command))
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, composer_require_instead_of_install):
assert (get_new_command(Command('composer udpate', assert (get_new_command(Command('composer udpate',
composer_not_command)) composer_not_command))
== 'composer update') == 'composer update')
assert (get_new_command(Command('composer pdate', assert (get_new_command(Command('composer pdate',
composer_not_command_one_of_this)) composer_not_command_one_of_this))
== 'composer selfupdate') == 'composer selfupdate')
assert (get_new_command(Command('composer install package',
composer_require_instead_of_install))
== 'composer require package')

View File

@ -5,12 +5,18 @@ from thefuck.utils import replace_argument, for_app
@for_app('composer') @for_app('composer')
def match(command): def match(command):
return (('did you mean this?' in command.output.lower() return (('did you mean this?' in command.output.lower()
or 'did you mean one of these?' in command.output.lower())) or 'did you mean one of these?' in command.output.lower())) or (
"install" in command.script_parts and "composer require" in command.output.lower()
)
def get_new_command(command): def get_new_command(command):
broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.output)[0] if "install" in command.script_parts and "composer require" in command.output.lower():
new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.output) broken_cmd, new_cmd = "install", "require"
if not new_cmd: else:
new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)', command.output) broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.output)[0]
return replace_argument(command.script, broken_cmd, new_cmd[0].strip()) new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.output)
if not new_cmd:
new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)', command.output)
new_cmd = new_cmd[0].strip()
return replace_argument(command.script, broken_cmd, new_cmd)