Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update list of 'Brew' commands #1426

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion tests/rules/test_brew_unknown_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,36 @@ def brew_unknown_cmd2():
return '''Error: Unknown command: instaa'''


@pytest.fixture
def brew_unknown_cmd_auto():
return '''Error: Unknown command: auto'''


@pytest.fixture
def brew_unknown_cmd_outdated():
return '''Error: Unknown command: outdate'''


def test_match(brew_unknown_cmd):
assert match(Command('brew inst', brew_unknown_cmd))
for command in _brew_commands():
assert not match(Command('brew ' + command, ''))


def test_get_new_command(brew_unknown_cmd, brew_unknown_cmd2):
def test_get_new_command(brew_unknown_cmd, brew_unknown_cmd2, brew_unknown_cmd_auto,
brew_unknown_cmd_outdated):
assert (get_new_command(Command('brew inst', brew_unknown_cmd))
== ['brew list', 'brew install', 'brew uninstall'])

cmds = get_new_command(Command('brew instaa', brew_unknown_cmd2))
assert 'brew install' in cmds
assert 'brew uninstall' in cmds

cmds = get_new_command(Command('brew auto', brew_unknown_cmd_auto))
assert 'brew audit' in cmds
assert 'brew autoremove' in cmds

cmds = get_new_command(Command('brew outdate', brew_unknown_cmd_outdated))
assert 'brew outdated' in cmds
assert 'brew update' in cmds
assert 'brew bottle' in cmds
26 changes: 20 additions & 6 deletions thefuck/rules/brew_unknown_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,38 @@ def _brew_commands():
except OSError:
pass

# Failback commands for testing (Based on Homebrew 0.9.5)
return ['info', 'home', 'options', 'install', 'uninstall',
'search', 'list', 'update', 'upgrade', 'pin', 'unpin',
'doctor', 'create', 'edit', 'cask']
# https://docs.brew.sh/Manpage
return [
'abv', 'analytics', 'autoremove', 'casks', 'cleanup', 'commands', 'completions',
'config', 'deps', 'desc', 'developer', 'docs', 'doctor', 'dr', 'fetch', 'formulae',
'gist-logs', 'help', 'home', 'homepage', 'info', 'install', 'leaves', 'link',
'ln', 'list', 'log', 'migrate', 'missing', 'nodenv-sync', 'options', 'outdated', 'pin',
'postinstall', 'pyenv-sync', 'rbenv-sync', 'readall', 'reinstall', 'remove', 'rm',
'search', 'setup-ruby', 'shellenv', 'tap-info', 'tap', 'uninstall', 'unlink',
'unpin', 'untap', 'update', 'update-reset', 'upgrade', 'uses',
# Developer Commands
'audit', 'bottle', 'bump', 'bump-cask-pr', 'bump-formula-pr', 'bump-revision',
'bump-unversioned-casks', 'cat', 'command', 'contributions', 'create', 'determine-test-runners',
'dispatch-build-bottle', 'edit', 'extract', 'formula', 'generate-cask-api', 'generate-formula-api',
'generate-man-completions', 'install-bundler-gems', 'irb', 'linkage', 'livecheck', 'lc',
'pr-automerge', 'pr-publish', 'pr-pull', 'pr-upload', 'prof', 'release', 'rubocop', 'ruby', 'sh',
'style', 'tap-new', 'test', 'tests', 'typecheck', 'tc', 'unbottled', 'unpack', 'update-license-data',
'update-maintainers', 'update-python-resources', 'update-sponsors', 'update-test', 'vendor-gems',
]


def match(command):
is_proper_command = ('brew' in command.script and
'Unknown command' in command.output)

if is_proper_command:
broken_cmd = re.findall(r'Error: Unknown command: ([a-z]+)',
broken_cmd = re.findall(r'Error: Unknown command: ([a-z-]+)',
command.output)[0]
return bool(get_closest(broken_cmd, _brew_commands()))
return False


def get_new_command(command):
broken_cmd = re.findall(r'Error: Unknown command: ([a-z]+)',
broken_cmd = re.findall(r'Error: Unknown command: ([a-z-]+)',
command.output)[0]
return replace_command(command, broken_cmd, _brew_commands())