From 985b2d9ec9d23a16d00a8288024722207189326a Mon Sep 17 00:00:00 2001 From: Vladimir Iakovlev Date: Sun, 15 Oct 2017 16:11:08 +0200 Subject: [PATCH] #N/A: Add `brew_cask_dependency` rule --- README.md | 1 + tests/rules/test_brew_cask_dependency.py | 35 ++++++++++++++++++++++++ thefuck/rules/brew_cask_dependency.py | 33 ++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/rules/test_brew_cask_dependency.py create mode 100644 thefuck/rules/brew_cask_dependency.py diff --git a/README.md b/README.md index ae1d58c6..5f5e3106 100644 --- a/README.md +++ b/README.md @@ -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; diff --git a/tests/rules/test_brew_cask_dependency.py b/tests/rules/test_brew_cask_dependency.py new file mode 100644 index 00000000..b30b020a --- /dev/null +++ b/tests/rules/test_brew_cask_dependency.py @@ -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 diff --git a/thefuck/rules/brew_cask_dependency.py b/thefuck/rules/brew_cask_dependency.py new file mode 100644 index 00000000..93c2915e --- /dev/null +++ b/thefuck/rules/brew_cask_dependency.py @@ -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