diff --git a/tests/rules/test_choco_install.py b/tests/rules/test_choco_install.py index 6f352718..bf5d2d41 100644 --- a/tests/rules/test_choco_install.py +++ b/tests/rules/test_choco_install.py @@ -7,6 +7,12 @@ from thefuck.types import Command ('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')]) + ('cinst logstitcher -y', 'cinst logstitcher.install -y'), + ('choco install logstitcher -y -n=test', 'choco install logstitcher.install -y -n=test'), + ('cinst logstitcher -y -n=test', 'cinst logstitcher.install -y -n=test'), + ('choco install logstitcher -y -n=test /env', 'choco install logstitcher.install -y -n=test /env'), + ('cinst logstitcher -y -n=test /env', 'cinst logstitcher.install -y -n=test /env'), + ('choco install chocolatey -y', 'choco install chocolatey.install -y'), + ('cinst chocolatey -y', 'cinst chocolatey.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 index cabbcec5..005b12fc 100644 --- a/thefuck/rules/choco_install.py +++ b/thefuck/rules/choco_install.py @@ -1,6 +1,5 @@ from thefuck.utils import for_app, which - @for_app("choco", "cinst") def match(command): return ((command.script.startswith('choco install') or 'cinst' in command.script_parts) @@ -10,17 +9,14 @@ def match(command): def get_new_command(command): # Find the argument that is the package name for script_part in command.script_parts: - if "choco" in script_part: + if script_part in ["choco", "cinst", "install"]: + # Need exact match (bc chocolatey is a package) continue - if "cinst" in script_part: + if script_part.startswith('-'): + # Leading hyphens are parameters; some packages contain them though continue - if "install" in script_part: - continue - if script_part.startswith('-'): # Some parameters start with hyphens; some packages contain them though - continue - if '=' in script_part: # Some paramaters contain '=' - continue - if '/' in script_part: # Some parameters contain slashes + if '=' in script_part or '/' in script_part: + # These are certainly parameters continue else: packageName = script_part