mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 12:28:41 +00:00
Add tsuru_login
rule
This commit is contained in:
parent
bfa3c905a3
commit
2117659c40
@ -185,6 +185,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
|||||||
* `switch_layout` – switches command from your local layout to en;
|
* `switch_layout` – switches command from your local layout to en;
|
||||||
* `systemctl` – correctly orders parameters of confusing `systemctl`;
|
* `systemctl` – correctly orders parameters of confusing `systemctl`;
|
||||||
* `test.py` – runs `py.test` instead of `test.py`;
|
* `test.py` – runs `py.test` instead of `test.py`;
|
||||||
|
* `tsuru_login.py` – runs `tsuru login` if not authenticated or session expired;
|
||||||
* `tmux` – fixes `tmux` commands;
|
* `tmux` – fixes `tmux` commands;
|
||||||
* `whois` – fixes `whois` command.
|
* `whois` – fixes `whois` command.
|
||||||
|
|
||||||
|
37
tests/rules/test_tsuru_login.py
Normal file
37
tests/rules/test_tsuru_login.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
import pytest
|
||||||
|
from thefuck.rules.tsuru_login import match, get_new_command
|
||||||
|
from tests.utils import Command
|
||||||
|
|
||||||
|
|
||||||
|
error_msg = (
|
||||||
|
"Error: you're not authenticated or your session has expired.",
|
||||||
|
("You're not authenticated or your session has expired. "
|
||||||
|
"Please use \"login\" command for authentication."),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command', [
|
||||||
|
Command(script='tsuru app-shell', stderr=error_msg[0]),
|
||||||
|
Command(script='tsuru app-log -f', stderr=error_msg[1]),
|
||||||
|
])
|
||||||
|
def test_match(command):
|
||||||
|
assert match(command, {})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command', [
|
||||||
|
Command(script='tsuru'),
|
||||||
|
Command(script='tsuru app-restart', stderr=('Error: unauthorized')),
|
||||||
|
Command(script='tsuru app-log -f', stderr=('Error: unparseable data')),
|
||||||
|
])
|
||||||
|
def test_not_match(command):
|
||||||
|
assert not match(command, {})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command, new_command', [
|
||||||
|
(Command('tsuru app-shell', stderr=error_msg[0]),
|
||||||
|
'tsuru login && tsuru app-shell'),
|
||||||
|
(Command('tsuru app-log -f', stderr=error_msg[1]),
|
||||||
|
'tsuru login && tsuru app-log -f'),
|
||||||
|
])
|
||||||
|
def test_get_new_command(command, new_command):
|
||||||
|
assert get_new_command(command, {}) == new_command
|
11
thefuck/rules/tsuru_login.py
Normal file
11
thefuck/rules/tsuru_login.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from thefuck import shells
|
||||||
|
|
||||||
|
|
||||||
|
def match(command, settings):
|
||||||
|
return (command.script.startswith('tsuru')
|
||||||
|
and 'not authenticated' in command.stderr
|
||||||
|
and 'session has expired' in command.stderr)
|
||||||
|
|
||||||
|
|
||||||
|
def get_new_command(command, settings):
|
||||||
|
return shells.and_('tsuru login', command.script)
|
Loading…
x
Reference in New Issue
Block a user