1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-21 20:38:54 +00:00

#157 Don't fail if can't get brew commands

This commit is contained in:
nvbn 2015-05-03 13:24:33 +02:00
parent 3ce8c1187c
commit 93c90d5758

View File

@ -2,7 +2,7 @@ import difflib
import os import os
import re import re
import subprocess import subprocess
import thefuck.logs
BREW_CMD_PATH = '/Library/Homebrew/cmd' BREW_CMD_PATH = '/Library/Homebrew/cmd'
TAP_PATH = '/Library/Taps' TAP_PATH = '/Library/Taps'
@ -10,7 +10,7 @@ TAP_CMD_PATH = '/%s/%s/cmd'
def _get_brew_path_prefix(): def _get_brew_path_prefix():
'''To get brew path''' """To get brew path"""
try: try:
return subprocess.check_output(['brew', '--prefix']).strip() return subprocess.check_output(['brew', '--prefix']).strip()
except: except:
@ -18,18 +18,18 @@ def _get_brew_path_prefix():
def _get_brew_commands(brew_path_prefix): def _get_brew_commands(brew_path_prefix):
'''To get brew default commands on local environment''' """To get brew default commands on local environment"""
brew_cmd_path = brew_path_prefix + BREW_CMD_PATH brew_cmd_path = brew_path_prefix + BREW_CMD_PATH
commands = (name.replace('.rb', '') for name in os.listdir(brew_cmd_path) commands = [name.replace('.rb', '') for name in os.listdir(brew_cmd_path)
if name.endswith('.rb')) if name.endswith('.rb')]
return commands return commands
def _get_brew_tap_specific_commands(brew_path_prefix): def _get_brew_tap_specific_commands(brew_path_prefix):
'''To get tap's specific commands """To get tap's specific commands
https://github.com/Homebrew/homebrew/blob/master/Library/brew.rb#L115''' https://github.com/Homebrew/homebrew/blob/master/Library/brew.rb#L115"""
commands = [] commands = []
brew_taps_path = brew_path_prefix + TAP_PATH brew_taps_path = brew_path_prefix + TAP_PATH
@ -61,17 +61,20 @@ def _get_directory_names_only(path):
return [d for d in os.listdir(path) return [d for d in os.listdir(path)
if os.path.isdir(os.path.join(path, d))] if os.path.isdir(os.path.join(path, d))]
brew_commands = []
brew_path_prefix = _get_brew_path_prefix() brew_path_prefix = _get_brew_path_prefix()
# Failback commands for testing (Based on Homebrew 0.9.5)
brew_commands = ['info', 'home', 'options', 'install', 'uninstall',
'search', 'list', 'update', 'upgrade', 'pin', 'unpin',
'doctor', 'create', 'edit']
if brew_path_prefix: if brew_path_prefix:
brew_commands += _get_brew_commands(brew_path_prefix) try:
brew_commands += _get_brew_tap_specific_commands(brew_path_prefix) brew_commands = _get_brew_commands(brew_path_prefix) \
else: + _get_brew_tap_specific_commands(brew_path_prefix)
# Failback commands for testing (Based on Homebrew 0.9.5) except OSError:
brew_commands = ['info', 'home', 'options', 'install', 'uninstall', pass
'search', 'list', 'update', 'upgrade', 'pin', 'unpin',
'doctor', 'create', 'edit']
def _get_similar_commands(command): def _get_similar_commands(command):