From 3c542a5b8cde085126fd9197b1ca6967c7adab1e Mon Sep 17 00:00:00 2001 From: DragonGhost7 Date: Sat, 28 Mar 2020 18:15:20 -0400 Subject: [PATCH] Added pacman invalid option rule (#960) * Added pacman invalid option rule * Added test * flake8 fixes * Test changes * Test fix * Typo - again * Travis test fix * More Travis * Even more travis * I hope im right here * Update README.md Co-Authored-By: Pablo Aguiar * Update thefuck/rules/pacman_invalid_option.py Co-Authored-By: Pablo Aguiar Co-authored-by: Pablo Aguiar --- README.md | 1 + tests/rules/test_pacman_invalid_option.py | 21 +++++++++++++++++++++ thefuck/rules/pacman_invalid_option.py | 14 ++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/rules/test_pacman_invalid_option.py create mode 100644 thefuck/rules/pacman_invalid_option.py diff --git a/README.md b/README.md index c78b871..57ca623 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,7 @@ The following rules are enabled by default on specific platforms only: * `dnf_no_such_command` – fixes mistyped DNF commands; * `nixos_cmd_not_found` – installs apps on NixOS; * `pacman` – installs app with `pacman` if it is not installed (uses `yay` or `yaourt` if available); +* `pacman_invalid_option` – replaces lowercase `pacman` options with uppercase. * `pacman_not_found` – fixes package name with `pacman`, `yay` or `yaourt`. * `yum_invalid_operation` – fixes invalid `yum` calls, like `yum isntall vim`; diff --git a/tests/rules/test_pacman_invalid_option.py b/tests/rules/test_pacman_invalid_option.py new file mode 100644 index 0000000..b454bcf --- /dev/null +++ b/tests/rules/test_pacman_invalid_option.py @@ -0,0 +1,21 @@ +from thefuck.rules.pacman_invalid_option import get_new_command, match +from thefuck.types import Command + +good_output = "community/shared_meataxe 1.0-3\n A set of programs for working with matrix representations over finite fields\n " + +bad_output = "error: invalid option '-s'" + + +def test_match(): + assert not match(Command('pacman -Ss meat', good_output)) + assert not match(Command('sudo pacman -Ss meat', good_output)) + assert match(Command('pacman -ss meat', bad_output)) + assert match(Command('sudo pacman -ss meat', bad_output)) + + +def test_get_new_command(): + new_command = get_new_command(Command('pacman -ss meat', bad_output)) + assert new_command == 'pacman -Ss meat' + + new_command = get_new_command(Command('sudo pacman -s meat', bad_output)) + assert new_command == 'sudo pacman -S meat' diff --git a/thefuck/rules/pacman_invalid_option.py b/thefuck/rules/pacman_invalid_option.py new file mode 100644 index 0000000..4104b46 --- /dev/null +++ b/thefuck/rules/pacman_invalid_option.py @@ -0,0 +1,14 @@ +from thefuck.specific.archlinux import archlinux_env +import re + + +def match(command): + return "error: invalid option '-s'" in command.output + + +def get_new_command(command): + opt = re.findall(r" -[dqrstuf]", command.script)[0] + return re.sub(opt, opt.upper(), command.script) + + +enabled_by_default = archlinux_env()