mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-18 12:06:04 +00:00
#N/A: Add brew_cask_dependency
rule
This commit is contained in:
parent
a906a751c8
commit
985b2d9ec9
@ -279,6 +279,7 @@ Enabled by default only on specific platforms:
|
||||
* `apt_get` – installs app from apt if it not installed (requires `python-commandnotfound` / `python3-commandnotfound`);
|
||||
* `apt_get_search` – changes trying to search using `apt-get` with searching using `apt-cache`;
|
||||
* `apt_invalid_operation` – fixes invalid `apt` and `apt-get` calls, like `apt-get isntall vim`;
|
||||
* `brew_cask_dependency` – installs cask dependencies;
|
||||
* `brew_install` – fixes formula name for `brew install`;
|
||||
* `brew_link` – adds `--overwrite --dry-run` if linking fails;
|
||||
* `brew_uninstall` – adds `--force` to `brew uninstall` if multiple versions were installed;
|
||||
|
35
tests/rules/test_brew_cask_dependency.py
Normal file
35
tests/rules/test_brew_cask_dependency.py
Normal file
@ -0,0 +1,35 @@
|
||||
import pytest
|
||||
from thefuck.rules.brew_cask_dependency import match, get_new_command
|
||||
from thefuck.types import Command
|
||||
|
||||
|
||||
output = '''sshfs: OsxfuseRequirement unsatisfied!
|
||||
|
||||
You can install with Homebrew-Cask:
|
||||
brew cask install osxfuse
|
||||
|
||||
You can download from:
|
||||
https://osxfuse.github.io/
|
||||
Error: An unsatisfied requirement failed this build.'''
|
||||
|
||||
|
||||
def test_match():
|
||||
command = Command('brew install sshfs', output)
|
||||
assert match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, output', [
|
||||
('brew link sshfs', output),
|
||||
('cat output', output),
|
||||
('brew install sshfs', '')])
|
||||
def test_not_match(script, output):
|
||||
command = Command(script, output)
|
||||
assert not match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('before, after', [
|
||||
('brew install sshfs',
|
||||
'brew cask install osxfuse && brew install sshfs')])
|
||||
def test_get_new_command(before, after):
|
||||
command = Command(before, output)
|
||||
assert get_new_command(command) == after
|
33
thefuck/rules/brew_cask_dependency.py
Normal file
33
thefuck/rules/brew_cask_dependency.py
Normal file
@ -0,0 +1,33 @@
|
||||
from thefuck.utils import for_app, eager
|
||||
from thefuck.shells import shell
|
||||
from thefuck.specific.brew import brew_available
|
||||
|
||||
|
||||
@for_app('brew')
|
||||
def match(command):
|
||||
return (u'install' in command.script_parts
|
||||
and u'brew cask install' in command.stderr)
|
||||
|
||||
|
||||
@eager
|
||||
def _get_cask_install_lines(output):
|
||||
for line in output.split('\n'):
|
||||
line = line.strip()
|
||||
if line.startswith('brew cask install'):
|
||||
yield line
|
||||
|
||||
|
||||
def _get_script_for_brew_cask(output):
|
||||
cask_install_lines = _get_cask_install_lines(output)
|
||||
if len(cask_install_lines) > 1:
|
||||
return shell.and_(*cask_install_lines)
|
||||
else:
|
||||
return cask_install_lines[0]
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
brew_cask_script = _get_script_for_brew_cask(command.output)
|
||||
return shell.and_(brew_cask_script, command.script)
|
||||
|
||||
|
||||
enabled_by_default = brew_available
|
Loading…
x
Reference in New Issue
Block a user