1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-31 10:11:14 +00:00

DNF module only enabled when DNF available and dynamically loads corrections

This commit is contained in:
Stef Pletinck 2017-10-05 16:40:17 +02:00
parent 16de31b9d6
commit d6b2c512f7
2 changed files with 21 additions and 31 deletions

View File

@ -1,36 +1,9 @@
import subprocess
import re
from thefuck.specific.sudo import sudo_support
from thefuck.utils import for_app, replace_command
from thefuck.specific.dnf import dnf_available
dnf_commands = [
'autoremove',
'check',
'check-update',
'clean',
'deplist',
'distro-sync',
'downgrade',
'group',
'help',
'history',
'info',
'install',
'list',
'makecache',
'mark',
'provides',
'reinstall',
'remove',
'repolist',
'repoquery',
'repository-packages',
'search',
'shell',
'swap',
'updateinfo',
'upgrade',
'upgrade-minimal'
]
regex = re.compile(r'No such command: (.*)\.')
@ -41,10 +14,24 @@ def match(command):
return 'no such command' in command.output.lower()
def _parse_operations(help_text_lines):
operation_regex = re.compile(b'^([a-z-]+) +', re.MULTILINE)
return operation_regex.findall(help_text_lines)
def _get_operations():
proc = subprocess.Popen(["dnf", '--help'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
lines = proc.stdout.read()
return _parse_operations(lines)
@sudo_support
def get_new_command(command):
misspelled_command = regex.findall(command.output)[0]
return replace_command(command, misspelled_command, dnf_commands)
return replace_command(command, misspelled_command, _get_operations())
enabled_by_default = True
enabled_by_default = dnf_available

3
thefuck/specific/dnf.py Normal file
View File

@ -0,0 +1,3 @@
from thefuck.utils import which
dnf_available = bool(which('dnf'))