mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 10:11:14 +00:00
Fix heroku_not_command for new stderr format
heroku updated its command suggestion formatting, so account for that. For example: $ heroku log ▸ log is not a heroku command. ▸ Perhaps you meant logs? ▸ Run heroku _ to run heroku logs. ▸ Run heroku help for a list of available commands. $ fuck heroku logs [enter/↑/↓/ctrl+c]
This commit is contained in:
parent
c3eca8234a
commit
d41cbb6810
@ -1,34 +1,31 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from tests.utils import Command
|
from tests.utils import Command
|
||||||
from thefuck.rules.heroku_not_command import match, get_new_command
|
from thefuck.rules.heroku_not_command import match, get_new_command
|
||||||
|
|
||||||
|
|
||||||
def suggest_stderr(cmd):
|
suggest_stderr = '''
|
||||||
return ''' ! `{}` is not a heroku command.
|
▸ log is not a heroku command.
|
||||||
! Perhaps you meant `logs`, `pg`.
|
▸ Perhaps you meant logs?
|
||||||
! See `heroku help` for a list of available commands.'''.format(cmd)
|
▸ Run heroku _ to run heroku logs.
|
||||||
|
▸ Run heroku help for a list of available commands.'''
|
||||||
|
|
||||||
|
|
||||||
no_suggest_stderr = ''' ! `aaaaa` is not a heroku command.
|
@pytest.mark.parametrize('cmd', ['log'])
|
||||||
! See `heroku help` for a list of available commands.'''
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('cmd', ['log', 'pge'])
|
|
||||||
def test_match(cmd):
|
def test_match(cmd):
|
||||||
assert match(
|
assert match(
|
||||||
Command('heroku {}'.format(cmd), stderr=suggest_stderr(cmd)))
|
Command('heroku {}'.format(cmd), stderr=suggest_stderr))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('script, stderr', [
|
@pytest.mark.parametrize('script, stderr', [
|
||||||
('cat log', suggest_stderr('log')),
|
('cat log', suggest_stderr)])
|
||||||
('heroku aaa', no_suggest_stderr)])
|
|
||||||
def test_not_match(script, stderr):
|
def test_not_match(script, stderr):
|
||||||
assert not match(Command(script, stderr=stderr))
|
assert not match(Command(script, stderr=stderr))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('cmd, result', [
|
@pytest.mark.parametrize('cmd, result', [
|
||||||
('log', ['heroku logs', 'heroku pg']),
|
('log', 'heroku logs')])
|
||||||
('pge', ['heroku pg', 'heroku logs'])])
|
|
||||||
def test_get_new_command(cmd, result):
|
def test_get_new_command(cmd, result):
|
||||||
command = Command('heroku {}'.format(cmd), stderr=suggest_stderr(cmd))
|
command = Command('heroku {}'.format(cmd), stderr=suggest_stderr)
|
||||||
assert get_new_command(command) == result
|
assert get_new_command(command) == result
|
||||||
|
@ -1,19 +1,11 @@
|
|||||||
import re
|
import re
|
||||||
from thefuck.utils import replace_command, for_app
|
from thefuck.utils import for_app
|
||||||
|
|
||||||
|
|
||||||
@for_app('heroku')
|
@for_app('heroku')
|
||||||
def match(command):
|
def match(command):
|
||||||
return 'is not a heroku command' in command.stderr and \
|
return 'Run heroku _ to run' in command.stderr
|
||||||
'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):
|
def get_new_command(command):
|
||||||
wrong = re.findall(r'`(\w+)` is not a heroku command', command.stderr)[0]
|
return re.findall('Run heroku _ to run ([^.]*)', command.stderr)[0]
|
||||||
return replace_command(command, wrong, _get_suggests(command.stderr))
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user