1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 15:04:42 +00:00

Fix: Improve Homebrew uninstallation feedback in 'mo remove'

When 'mole remove' is used and Mole was installed via Homebrew, the script
now provides more explicit feedback if the 'brew uninstall --force mole'
command fails. Previously, errors were silently ignored.

This change ensures that if Homebrew uninstallation encounters an issue,
the user is informed with the error output and instructed on how to
manually complete the uninstallation, preventing inconsistencies where
Homebrew still believes Mole is installed.

Additionally, a minor improvement to config_dir resolution in update_mole
was included for robustness.
This commit is contained in:
Tw93
2025-12-31 00:17:40 +08:00
parent 13e735d58a
commit 6cf6a995cd

44
mole
View File

@@ -432,11 +432,15 @@ update_mole() {
# Run installer with visible output (but capture for error handling) # Run installer with visible output (but capture for error handling)
local install_output local install_output
local update_tag="V${latest#V}" local update_tag="V${latest#V}"
if install_output=$(MOLE_VERSION="$update_tag" "$tmp_installer" --prefix "$install_dir" --config "$HOME/.config/mole" --update 2>&1); then local config_dir="${MOLE_CONFIG_DIR:-$SCRIPT_DIR}"
if [[ ! -f "$config_dir/lib/core/common.sh" ]]; then
config_dir="$HOME/.config/mole"
fi
if install_output=$(MOLE_VERSION="$update_tag" "$tmp_installer" --prefix "$install_dir" --config "$config_dir" --update 2>&1); then
process_install_output "$install_output" process_install_output "$install_output"
else else
# Retry without --update flag # Retry without --update flag
if install_output=$(MOLE_VERSION="$update_tag" "$tmp_installer" --prefix "$install_dir" --config "$HOME/.config/mole" 2>&1); then if install_output=$(MOLE_VERSION="$update_tag" "$tmp_installer" --prefix "$install_dir" --config "$config_dir" 2>&1); then
process_install_output "$install_output" process_install_output "$install_output"
else else
if [[ -t 1 ]]; then stop_inline_spinner; fi if [[ -t 1 ]]; then stop_inline_spinner; fi
@@ -461,11 +465,27 @@ remove_mole() {
fi fi
local is_homebrew=false local is_homebrew=false
local brew_cmd=""
local brew_has_mole="false"
local -a manual_installs=() local -a manual_installs=()
local -a alias_installs=() local -a alias_installs=()
if command -v brew > /dev/null 2>&1; then
brew_cmd="brew"
elif [[ -x "/opt/homebrew/bin/brew" ]]; then
brew_cmd="/opt/homebrew/bin/brew"
elif [[ -x "/usr/local/bin/brew" ]]; then
brew_cmd="/usr/local/bin/brew"
fi
if [[ -n "$brew_cmd" ]]; then
if "$brew_cmd" list --formula 2> /dev/null | grep -q "^mole$"; then
brew_has_mole="true"
fi
fi
# Check Homebrew # Check Homebrew
if is_homebrew_install; then if [[ "$brew_has_mole" == "true" ]] || is_homebrew_install; then
is_homebrew=true is_homebrew=true
fi fi
@@ -557,11 +577,25 @@ remove_mole() {
;; ;;
esac esac
# Remove Homebrew installation (silent) # Remove Homebrew installation
local has_error=false local has_error=false
if [[ "$is_homebrew" == "true" ]]; then if [[ "$is_homebrew" == "true" ]]; then
if ! brew uninstall --force mole > /dev/null 2>&1; then if [[ -z "$brew_cmd" ]]; then
log_error "Homebrew command not found. Please ensure Homebrew is installed and in your PATH."
log_warning "You may need to manually run: brew uninstall --force mole"
exit 1
fi
log_admin "Attempting to uninstall Mole via Homebrew..."
local brew_uninstall_output
if ! brew_uninstall_output=$("$brew_cmd" uninstall --force mole 2>&1); then
has_error=true has_error=true
log_error "Homebrew uninstallation failed:"
printf "%s\n" "$brew_uninstall_output" | sed "s/^/${RED} | ${NC}/" >&2
log_warning "Please manually run: ${YELLOW}brew uninstall --force mole${NC}"
echo "" # Add a blank line for readability
else
log_success "Mole uninstalled via Homebrew."
fi fi
fi fi
# Remove manual installations # Remove manual installations