mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 06:38:32 +00:00
trying to add brew cask reinstall
This commit is contained in:
parent
d10fc80fa5
commit
0b78827602
@ -315,6 +315,7 @@ The following rules are enabled by default on specific platforms only:
|
||||
* `apt_list_upgradable` – helps you run `apt list --upgradable` after `apt update`;
|
||||
* `apt_upgrade` – helps you run `apt upgrade` after `apt list --upgradable`;
|
||||
* `brew_cask_dependency` – installs cask dependencies;
|
||||
* `brew_cask_reinstall` – turns `brew cask install <formula>` into `brew cask reinstall <formula>`;
|
||||
* `brew_install` – fixes formula name for `brew install`;
|
||||
* `brew_reinstall` – turns `brew install <formula>` into `brew reinstall <formula>`;
|
||||
* `brew_link` – adds `--overwrite --dry-run` if linking fails;
|
||||
|
28
tests/rules/test_brew_cask_reinstall.py
Normal file
28
tests/rules/test_brew_cask_reinstall.py
Normal file
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
from thefuck.types import Command
|
||||
from thefuck.rules.brew_cask_reinstall import get_new_command, match
|
||||
|
||||
|
||||
output = ("Warning: Cask 'thefuck' is already installed.\n\nTo "
|
||||
"re-install thefuck, run\n `brew cask reinstall thefuck`")
|
||||
|
||||
|
||||
def test_match():
|
||||
command = Command('brew cask install thefuck', output)
|
||||
assert match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script', [
|
||||
'brew cask reinstall thefuck',
|
||||
'brew install foo'])
|
||||
def test_not_match(script):
|
||||
assert not match(Command(script, ''))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, formula, ', [
|
||||
('brew install foo', 'foo'),
|
||||
('brew install bar zap', 'bar zap')])
|
||||
def test_get_new_command(script, formula):
|
||||
command = Command(script, output)
|
||||
new_command = 'brew cask reinstall {}'.format(formula)
|
||||
assert get_new_command(command) == new_command
|
17
thefuck/rules/brew_cask_reinstall.py
Normal file
17
thefuck/rules/brew_cask_reinstall.py
Normal file
@ -0,0 +1,17 @@
|
||||
import re
|
||||
from thefuck.utils import for_app
|
||||
|
||||
|
||||
warning_regex = re.compile(r'Warning: Cask \'(?:.(?!is ))+\' is already installed.\n\n')
|
||||
message_regex = re.compile(r'To re-install (?:(?!, ).)+, run\n `brew cask reinstall [^`]+`')
|
||||
|
||||
|
||||
@for_app('brew', at_least=2)
|
||||
def match(command):
|
||||
return ('cask install' in command.script
|
||||
and warning_regex.search(command.output)
|
||||
and message_regex.search(command.output))
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
return command.script.replace('install', 'reinstall')
|
Loading…
x
Reference in New Issue
Block a user