diff --git a/README.md b/README.md index 0b6435e0..bab72bb5 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,7 @@ following rules are enabled by default: * `cd_mkdir` – creates directories before cd'ing into them; * `cd_parent` – changes `cd..` to `cd ..`; * `chmod_x` – add execution bit; +* `choco_install` – append common suffixes for chocolatey packages; * `composer_not_command` – fixes composer command name; * `cp_omitting_directory` – adds `-a` when you `cp` directory; * `cpp11` – adds missing `-std=c++11` to `g++` or `clang++`; diff --git a/tests/rules/test_choco_install.py b/tests/rules/test_choco_install.py new file mode 100644 index 00000000..6f352718 --- /dev/null +++ b/tests/rules/test_choco_install.py @@ -0,0 +1,12 @@ +import pytest +from thefuck.rules.choco_install import get_new_command +from thefuck.types import Command + + +@pytest.mark.parametrize('before, after', [ + ('choco install logstitcher', 'choco install logstitcher.install'), + ('cinst logstitcher', 'cinst logstitcher.install'), + ('choco install logstitcher -y', 'choco install logstitcher.install -y'), + ('cinst logstitcher -y', 'cinst logstitcher.install -y')]) +def test_get_new_command(before, after): + assert (get_new_command(Command(before, '')) == after) diff --git a/thefuck/rules/choco_install.py b/thefuck/rules/choco_install.py new file mode 100644 index 00000000..3c884b05 --- /dev/null +++ b/thefuck/rules/choco_install.py @@ -0,0 +1,29 @@ +def match(command): + return (('choco install' in command.script_parts or 'cinst' in command.script_parts) + and 'Installing the following packages' in command.output) + + +def get_new_command(command): + cmdList = command.script.split(' ') + packageName = "" + # Find the argument that is the package name + for i in cmdList: + print(i) + if "choco" in i: + continue + if "cinst" in i: + continue + if "install" in i: + continue + if i.startswith('-'): # Some parameters start with hyphens; some packages contain them though + continue + if '=' in i: # Some paramaters contain '=' + continue + if '/' in i: # Some parameters contain slashes + continue + else: + packageName = i + # Find the name of the broken package, and append metapackage names + if not packageName: + return False + return(command.script.replace(packageName, packageName + ".install"))