1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 14:48:49 +00:00

adding dnf install rule

This commit is contained in:
iury 2016-01-05 23:00:09 -02:00
parent 1b12cd85e9
commit d7e62e4be8
3 changed files with 38 additions and 0 deletions

View File

@ -216,6 +216,7 @@ Enabled by default only on specific platforms:
* `brew_upgrade` – appends `--all` to `brew upgrade` as per Homebrew's new behaviour;
* `pacman` – installs app with `pacman` if it is not installed (uses `yaourt` if available);
* `pacman_not_found` – fixes package name with `pacman` or `yaourt`.
* `dnf_install` – fixes `dnf install` command
Bundled, but not enabled by default:

View File

@ -0,0 +1,13 @@
import pytest
from mock import Mock, patch
from thefuck.rules import dnf_install
from tests.utils import Command
@pytest.mark.parametrize('command, new_command', [
(Command('dfn install python'), 'sudo dnf install python'),
(Command('dnf istall python'), 'sudo dnf install python'),
(Command('dfn install python'), 'sudo dnf install python'),
(Command('dfn install python ruby'), 'sudo dnf install python ruby')])
def test_get_new_command(command, new_command):
assert dnf_install.get_new_command(command) == new_command

View File

@ -0,0 +1,24 @@
from thefuck import shells
from thefuck.utils import memoize
def get_packages(command):
splitted_command = command.script.split()
if splitted_command[0] == 'sudo':
return splitted_command[3:]
return splitted_command[2:]
def match(command):
typos = ('dfn install', 'dnf istall', 'dfn istall')
patterns = ("not found", "No such command")
stderr = command.stderr
found_pattern = any(pattern in stderr for pattern in patterns)
found_typo = any(typo in command.script for typo in typos)
return found_pattern and found_typo
def get_new_command(command):
packages = get_packages(command)
return 'sudo dnf install {}'.format(' '.join(packages))