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:
parent
4f165bf6df
commit
05e0696ac7
@ -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++`;
|
||||
|
12
tests/rules/test_choco_install.py
Normal file
12
tests/rules/test_choco_install.py
Normal 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)
|
29
thefuck/rules/choco_install.py
Normal file
29
thefuck/rules/choco_install.py
Normal 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"))
|
Loading…
x
Reference in New Issue
Block a user