From 8b2ba5762c6fa3ef9b40d1624d4c76accb40bfb1 Mon Sep 17 00:00:00 2001 From: nvbn Date: Sat, 18 Apr 2015 23:19:34 +0200 Subject: [PATCH] Add support of `lein` "is not task" --- README.md | 11 +++++++++++ setup.py | 2 +- tests/rules/test_lein_not_task.py | 22 ++++++++++++++++++++++ thefuck/rules/lein_not_task.py | 15 +++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/rules/test_lein_not_task.py create mode 100644 thefuck/rules/lein_not_task.py diff --git a/README.md b/README.md index 8815a69..b4673ce 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,17 @@ Did you mean this? ➜ fuck git branch * master + +➜ lein rpl +'rpl' is not a task. See 'lein help'. + +Did you mean this? + repl + +➜ fuck +nREPL server started on port 54848 on host 127.0.0.1 - nrepl://127.0.0.1:54848 +REPL-y 0.3.1 +... ``` ## Installation diff --git a/setup.py b/setup.py index 5759cdc..b6faace 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup(name='thefuck', - version=1.11, + version=1.12, description="Magnificent app which corrects your previous console command", author='Vladimir Iakovlev', author_email='nvbn.rm@gmail.com', diff --git a/tests/rules/test_lein_not_task.py b/tests/rules/test_lein_not_task.py new file mode 100644 index 0000000..35975b8 --- /dev/null +++ b/tests/rules/test_lein_not_task.py @@ -0,0 +1,22 @@ +import pytest +from mock import Mock +from thefuck.rules.lein_not_task import match, get_new_command + + +@pytest.fixture +def is_not_task(): + return ''''rpl' is not a task. See 'lein help'. + +Did you mean this? + repl +''' + + +def test_match(is_not_task): + assert match(Mock(script='lein rpl', stderr=is_not_task), None) + assert not match(Mock(script='ls', stderr=is_not_task), None) + + +def test_get_new_command(is_not_task): + assert get_new_command(Mock(script='lein rpl --help', stderr=is_not_task), + None) == 'lein repl --help' diff --git a/thefuck/rules/lein_not_task.py b/thefuck/rules/lein_not_task.py new file mode 100644 index 0000000..efc25a1 --- /dev/null +++ b/thefuck/rules/lein_not_task.py @@ -0,0 +1,15 @@ +import re + + +def match(command, settings): + return (command.script.startswith('lein') + and "is not a task. See 'lein help'" in command.stderr + and 'Did you mean this?' in command.stderr) + + +def get_new_command(command, settings): + broken_cmd = re.findall(r"'([^']*)' is not a task", + command.stderr)[0] + new_cmd = re.findall(r'Did you mean this\?\n\s*([^\n]*)', + command.stderr)[0] + return command.script.replace(broken_cmd, new_cmd, 1)