From 2b3e8dc62ae17a0ab0f268241e6a92fcd212e560 Mon Sep 17 00:00:00 2001 From: Bastian Gebhardt Date: Thu, 20 Aug 2015 00:23:33 +0200 Subject: [PATCH 1/2] Adding rule for trying to search using apt-get --- README.md | 1 + tests/rules/test_apt_get_search.py | 20 ++++++++++++++++++++ thefuck/rules/apt_get_search.py | 9 +++++++++ 3 files changed, 30 insertions(+) create mode 100644 tests/rules/test_apt_get_search.py create mode 100644 thefuck/rules/apt_get_search.py diff --git a/README.md b/README.md index 9646e33..3d94cc2 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: Enabled by default only on specific platforms: * `apt_get` – installs app from apt if it not installed; +* `apt_get_search` – changes trying to search using `apt-get` with searching using `apt-cache` * `brew_install` – fixes formula name for `brew install`; * `brew_unknown_command` – fixes wrong brew commands, for example `brew docto/brew doctor`; * `brew_upgrade` – appends `--all` to `brew upgrade` as per Homebrew's new behaviour; diff --git a/tests/rules/test_apt_get_search.py b/tests/rules/test_apt_get_search.py new file mode 100644 index 0000000..febbce6 --- /dev/null +++ b/tests/rules/test_apt_get_search.py @@ -0,0 +1,20 @@ +import pytest +from thefuck.rules.apt_get_search import get_new_command, match +from tests.utils import Command + + +def test_match(): + assert match(Command('apt-get search foo'), None) + + +@pytest.mark.parametrize('command', [ + Command('apt-cache search foo'), + Command('aptitude search foo'), + Command('apt search foo') +]) +def test_not_match(command): + assert not match(command, None) + + +def test_get_new_command(): + assert get_new_command(Command('apt-get search foo'), None) == 'apt-cache search foo' diff --git a/thefuck/rules/apt_get_search.py b/thefuck/rules/apt_get_search.py new file mode 100644 index 0000000..6c06ddd --- /dev/null +++ b/thefuck/rules/apt_get_search.py @@ -0,0 +1,9 @@ +import re + + +def match(command, settings): + return command.script.startswith('apt-get search') + + +def get_new_command(command, settings): + return re.sub(r'^apt-get', 'apt-cache', command.script) From 8cbe2368455b5ab0b4bf90b0bfbc11b66eaed8a6 Mon Sep 17 00:00:00 2001 From: Bastian Gebhardt Date: Thu, 20 Aug 2015 00:23:33 +0200 Subject: [PATCH 2/2] Adding rule for trying to search using apt-get --- tests/rules/test_apt_get_search.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/rules/test_apt_get_search.py b/tests/rules/test_apt_get_search.py index febbce6..82f3d04 100644 --- a/tests/rules/test_apt_get_search.py +++ b/tests/rules/test_apt_get_search.py @@ -10,7 +10,12 @@ def test_match(): @pytest.mark.parametrize('command', [ Command('apt-cache search foo'), Command('aptitude search foo'), - Command('apt search foo') + Command('apt search foo'), + Command('apt-get install foo'), + Command('apt-get source foo'), + Command('apt-get clean'), + Command('apt-get remove'), + Command('apt-get update') ]) def test_not_match(command): assert not match(command, None)