mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-14 17:08:45 +00:00
DNF module only enabled when DNF available and dynamically loads corrections
This commit is contained in:
parent
16de31b9d6
commit
d6b2c512f7
@ -1,36 +1,9 @@
|
|||||||
|
import subprocess
|
||||||
import re
|
import re
|
||||||
from thefuck.specific.sudo import sudo_support
|
from thefuck.specific.sudo import sudo_support
|
||||||
from thefuck.utils import for_app, replace_command
|
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: (.*)\.')
|
regex = re.compile(r'No such command: (.*)\.')
|
||||||
|
|
||||||
@ -41,10 +14,24 @@ def match(command):
|
|||||||
return 'no such command' in command.output.lower()
|
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
|
@sudo_support
|
||||||
def get_new_command(command):
|
def get_new_command(command):
|
||||||
misspelled_command = regex.findall(command.output)[0]
|
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
3
thefuck/specific/dnf.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from thefuck.utils import which
|
||||||
|
|
||||||
|
dnf_available = bool(which('dnf'))
|
Loading…
x
Reference in New Issue
Block a user