mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-22 12:58:33 +00:00
#N/A Add heroku_not_command
rule
This commit is contained in:
parent
46f918718f
commit
b4392ba706
@ -148,7 +148,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
|||||||
* `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch;
|
* `git_branch_list` – catches `git branch list` in place of `git branch` and removes created branch;
|
||||||
* `git_checkout` – fixes branch name or creates new branch;
|
* `git_checkout` – fixes branch name or creates new branch;
|
||||||
* `git_diff_staged` – adds `--staged` to previous `git diff` with unexpected output;
|
* `git_diff_staged` – adds `--staged` to previous `git diff` with unexpected output;
|
||||||
* `git_no_command` – fixes wrong git commands like `git brnch`;
|
* `git_not_command` – fixes wrong git commands like `git brnch`;
|
||||||
* `git_pull` – sets upstream before executing previous `git pull`;
|
* `git_pull` – sets upstream before executing previous `git pull`;
|
||||||
* `git_pull_clone` – clones instead of pulling when the repo does not exist;
|
* `git_pull_clone` – clones instead of pulling when the repo does not exist;
|
||||||
* `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`;
|
* `git_push` – adds `--set-upstream origin $branch` to previous failed `git push`;
|
||||||
@ -157,6 +157,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
|||||||
* `go_run` – appends `.go` extension when compiling/running Go programs
|
* `go_run` – appends `.go` extension when compiling/running Go programs
|
||||||
* `grep_recursive` – adds `-r` when you trying to grep directory;
|
* `grep_recursive` – adds `-r` when you trying to grep directory;
|
||||||
* `has_exists_script` – prepends `./` when script/binary exists;
|
* `has_exists_script` – prepends `./` when script/binary exists;
|
||||||
|
* `heroku_no_command` – fixes wrong heroku commands like `heroku log`;
|
||||||
* `history` – tries to replace command with most similar command from history;
|
* `history` – tries to replace command with most similar command from history;
|
||||||
* `java` – removes `.java` extension when running Java programs;
|
* `java` – removes `.java` extension when running Java programs;
|
||||||
* `javac` – appends missing `.java` when compiling Java files;
|
* `javac` – appends missing `.java` when compiling Java files;
|
||||||
|
34
tests/rules/test_heroku_not_command.py
Normal file
34
tests/rules/test_heroku_not_command.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import pytest
|
||||||
|
from tests.utils import Command
|
||||||
|
from thefuck.rules.heroku_not_command import match, get_new_command
|
||||||
|
|
||||||
|
|
||||||
|
def suggest_stderr(cmd):
|
||||||
|
return ''' ! `{}` is not a heroku command.
|
||||||
|
! Perhaps you meant `logs`, `pg`.
|
||||||
|
! See `heroku help` for a list of available commands.'''.format(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
no_suggest_stderr = ''' ! `aaaaa` is not a heroku command.
|
||||||
|
! See `heroku help` for a list of available commands.'''
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('cmd', ['log', 'pge'])
|
||||||
|
def test_match(cmd):
|
||||||
|
assert match(
|
||||||
|
Command('heroku {}'.format(cmd), stderr=suggest_stderr(cmd)), None)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('script, stderr', [
|
||||||
|
('cat log', suggest_stderr('log')),
|
||||||
|
('heroku aaa', no_suggest_stderr)])
|
||||||
|
def test_not_match(script, stderr):
|
||||||
|
assert not match(Command(script, stderr=stderr), None)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('cmd, result', [
|
||||||
|
('log', 'heroku logs'),
|
||||||
|
('pge', 'heroku pg')])
|
||||||
|
def test_get_new_command(cmd, result):
|
||||||
|
command = Command('heroku {}'.format(cmd), stderr=suggest_stderr(cmd))
|
||||||
|
assert get_new_command(command, None) == result
|
20
thefuck/rules/heroku_not_command.py
Normal file
20
thefuck/rules/heroku_not_command.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import re
|
||||||
|
from thefuck.utils import get_closest
|
||||||
|
|
||||||
|
|
||||||
|
def match(command, settings):
|
||||||
|
return command.script.startswith('heroku') and \
|
||||||
|
'is not a heroku command' in command.stderr and \
|
||||||
|
'Perhaps you meant' in command.stderr
|
||||||
|
|
||||||
|
|
||||||
|
def _get_suggests(stderr):
|
||||||
|
for line in stderr.split('\n'):
|
||||||
|
if 'Perhaps you meant' in line:
|
||||||
|
return re.findall(r'`([^`]+)`', line)
|
||||||
|
|
||||||
|
|
||||||
|
def get_new_command(command, settings):
|
||||||
|
wrong = re.findall(r'`(\w+)` is not a heroku command', command.stderr)[0]
|
||||||
|
correct = get_closest(wrong, _get_suggests(command.stderr))
|
||||||
|
return command.script.replace(' {}'.format(wrong), ' {}'.format(correct), 1)
|
Loading…
x
Reference in New Issue
Block a user