mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-20 20:09:07 +00:00
Add a new tsuru_not_command
rule
This commit is contained in:
parent
4e854a575e
commit
65a25d5448
@ -188,6 +188,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
||||
* `systemctl` – correctly orders parameters of confusing `systemctl`;
|
||||
* `test.py` – runs `py.test` instead of `test.py`;
|
||||
* `tsuru_login` – runs `tsuru login` if not authenticated or session expired;
|
||||
* `tsuru_not_command` – fixes wrong tsuru commands like `tsuru shell`;
|
||||
* `tmux` – fixes `tmux` commands;
|
||||
* `whois` – fixes `whois` command.
|
||||
|
||||
|
90
tests/rules/test_tsuru_not_command.py
Normal file
90
tests/rules/test_tsuru_not_command.py
Normal file
@ -0,0 +1,90 @@
|
||||
import pytest
|
||||
|
||||
from tests.utils import Command
|
||||
from thefuck.rules.tsuru_not_command import match, get_new_command
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('tsuru log', stderr=(
|
||||
'tsuru: "tchururu" is not a tsuru command. See "tsuru help".\n'
|
||||
'\nDid you mean?\n'
|
||||
'\tapp-log\n'
|
||||
'\tlogin\n'
|
||||
'\tlogout\n'
|
||||
)),
|
||||
Command('tsuru app-l', stderr=(
|
||||
'tsuru: "tchururu" is not a tsuru command. See "tsuru help".\n'
|
||||
'\nDid you mean?\n'
|
||||
'\tapp-list\n'
|
||||
'\tapp-log\n'
|
||||
)),
|
||||
Command('tsuru user-list', stderr=(
|
||||
'tsuru: "tchururu" is not a tsuru command. See "tsuru help".\n'
|
||||
'\nDid you mean?\n'
|
||||
'\tteam-user-list\n'
|
||||
)),
|
||||
Command('tsuru targetlist', stderr=(
|
||||
'tsuru: "tchururu" is not a tsuru command. See "tsuru help".\n'
|
||||
'\nDid you mean?\n'
|
||||
'\ttarget-list\n'
|
||||
)),
|
||||
])
|
||||
def test_match(command):
|
||||
assert match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command('tsuru tchururu', stderr=(
|
||||
'tsuru: "tchururu" is not a tsuru command. See "tsuru help".\n'
|
||||
'\nDid you mean?\n'
|
||||
)),
|
||||
Command('tsuru version', stderr='tsuru version 0.16.0.'),
|
||||
Command('tsuru help', stderr=(
|
||||
'tsuru version 0.16.0.\n'
|
||||
'\nUsage: tsuru command [args]\n'
|
||||
)),
|
||||
Command('tsuru platform-list', stderr=(
|
||||
'- java\n'
|
||||
'- logstashgiro\n'
|
||||
'- newnode\n'
|
||||
'- nodejs\n'
|
||||
'- php\n'
|
||||
'- python\n'
|
||||
'- python3\n'
|
||||
'- ruby\n'
|
||||
'- ruby20\n'
|
||||
'- static\n'
|
||||
)),
|
||||
Command('tsuru env-get', stderr='Error: App thefuck not found.'),
|
||||
])
|
||||
def test_not_match(command):
|
||||
assert not match(command, None)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('tsuru log', stderr=(
|
||||
'tsuru: "log" is not a tsuru command. See "tsuru help".\n'
|
||||
'\nDid you mean?\n'
|
||||
'\tapp-log\n'
|
||||
'\tlogin\n'
|
||||
'\tlogout\n'
|
||||
)), 'tsuru login'),
|
||||
(Command('tsuru app-l', stderr=(
|
||||
'tsuru: "app-l" is not a tsuru command. See "tsuru help".\n'
|
||||
'\nDid you mean?\n'
|
||||
'\tapp-list\n'
|
||||
'\tapp-log\n'
|
||||
)), 'tsuru app-log'),
|
||||
(Command('tsuru user-list', stderr=(
|
||||
'tsuru: "user-list" is not a tsuru command. See "tsuru help".\n'
|
||||
'\nDid you mean?\n'
|
||||
'\tteam-user-list\n'
|
||||
)), 'tsuru team-user-list'),
|
||||
(Command('tsuru targetlist', stderr=(
|
||||
'tsuru: "targetlist" is not a tsuru command. See "tsuru help".\n'
|
||||
'\nDid you mean?\n'
|
||||
'\ttarget-list\n'
|
||||
)), 'tsuru target-list'),
|
||||
])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert get_new_command(command, None) == new_command
|
18
thefuck/rules/tsuru_not_command.py
Normal file
18
thefuck/rules/tsuru_not_command.py
Normal file
@ -0,0 +1,18 @@
|
||||
import re
|
||||
from thefuck.utils import (get_closest, replace_argument,
|
||||
get_all_matched_commands)
|
||||
|
||||
|
||||
def match(command, settings):
|
||||
return (command.script.startswith('tsuru ')
|
||||
and ' is not a tsuru command. See "tsuru help".' in command.stderr
|
||||
and '\nDid you mean?\n\t' in command.stderr)
|
||||
|
||||
|
||||
def get_new_command(command, settings):
|
||||
broken_cmd = re.findall(r'tsuru: "([^"]*)" is not a tsuru command',
|
||||
command.stderr)[0]
|
||||
new_cmd = get_closest(broken_cmd,
|
||||
get_all_matched_commands(command.stderr))
|
||||
return replace_argument(command.script, broken_cmd, new_cmd)
|
||||
|
Loading…
x
Reference in New Issue
Block a user