diff --git a/thefuck/rules/dnf_no_such_command.py b/thefuck/rules/dnf_no_such_command.py index 227ca03e..27d353a0 100644 --- a/thefuck/rules/dnf_no_such_command.py +++ b/thefuck/rules/dnf_no_such_command.py @@ -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 diff --git a/thefuck/specific/dnf.py b/thefuck/specific/dnf.py new file mode 100644 index 00000000..0e34cfd9 --- /dev/null +++ b/thefuck/specific/dnf.py @@ -0,0 +1,3 @@ +from thefuck.utils import which + +dnf_available = bool(which('dnf'))