mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-22 12:58:33 +00:00
#157 Don't fail if can't get brew commands
This commit is contained in:
parent
3ce8c1187c
commit
93c90d5758
@ -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,18 +61,21 @@ 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()
|
||||||
|
|
||||||
if brew_path_prefix:
|
|
||||||
brew_commands += _get_brew_commands(brew_path_prefix)
|
|
||||||
brew_commands += _get_brew_tap_specific_commands(brew_path_prefix)
|
|
||||||
else:
|
|
||||||
# Failback commands for testing (Based on Homebrew 0.9.5)
|
# Failback commands for testing (Based on Homebrew 0.9.5)
|
||||||
brew_commands = ['info', 'home', 'options', 'install', 'uninstall',
|
brew_commands = ['info', 'home', 'options', 'install', 'uninstall',
|
||||||
'search', 'list', 'update', 'upgrade', 'pin', 'unpin',
|
'search', 'list', 'update', 'upgrade', 'pin', 'unpin',
|
||||||
'doctor', 'create', 'edit']
|
'doctor', 'create', 'edit']
|
||||||
|
|
||||||
|
if brew_path_prefix:
|
||||||
|
try:
|
||||||
|
brew_commands = _get_brew_commands(brew_path_prefix) \
|
||||||
|
+ _get_brew_tap_specific_commands(brew_path_prefix)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def _get_similar_commands(command):
|
def _get_similar_commands(command):
|
||||||
return difflib.get_close_matches(command, brew_commands)
|
return difflib.get_close_matches(command, brew_commands)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user