1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 06:38:32 +00:00

Add choco_install rule

Adds a rule to append '.install' to a chocolatey install command that
failed because of a non-existent package.

TODO: add support for other suffixes (.portable), find more parameter
cases
This commit is contained in:
Philip Arola 2019-10-28 19:46:32 -07:00
parent 4f165bf6df
commit 05e0696ac7
3 changed files with 42 additions and 0 deletions

View File

@ -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++`;

View File

@ -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)

View File

@ -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"))