mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-20 09:39:01 +00:00
adding dnf install rule
This commit is contained in:
parent
1b12cd85e9
commit
d7e62e4be8
@ -216,6 +216,7 @@ Enabled by default only on specific platforms:
|
|||||||
* `brew_upgrade` – appends `--all` to `brew upgrade` as per Homebrew's new behaviour;
|
* `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` – installs app with `pacman` if it is not installed (uses `yaourt` if available);
|
||||||
* `pacman_not_found` – fixes package name with `pacman` or `yaourt`.
|
* `pacman_not_found` – fixes package name with `pacman` or `yaourt`.
|
||||||
|
* `dnf_install` – fixes `dnf install` command
|
||||||
|
|
||||||
Bundled, but not enabled by default:
|
Bundled, but not enabled by default:
|
||||||
|
|
||||||
|
13
tests/rules/test_dnf_install.py
Normal file
13
tests/rules/test_dnf_install.py
Normal 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
|
24
thefuck/rules/dnf_install.py
Normal file
24
thefuck/rules/dnf_install.py
Normal 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))
|
Loading…
x
Reference in New Issue
Block a user