mirror of
https://github.com/tw93/Mole.git
synced 2026-03-22 18:30:08 +00:00
refactor(clean): simplify Go cache whitelist logic
- Fix undefined ICON_SKIP, use ICON_SUCCESS instead - Reduce code from 46 to 27 lines with early return pattern - Consistent styling with other whitelist skip messages
This commit is contained in:
@@ -116,52 +116,35 @@ clean_dev_python() {
|
||||
}
|
||||
# Go build/module caches.
|
||||
clean_dev_go() {
|
||||
if command -v go > /dev/null 2>&1; then
|
||||
# Get Go cache paths
|
||||
local go_build_cache
|
||||
local go_mod_cache
|
||||
command -v go > /dev/null 2>&1 || return 0
|
||||
|
||||
local go_build_cache go_mod_cache
|
||||
go_build_cache=$(go env GOCACHE 2> /dev/null || echo "$HOME/Library/Caches/go-build")
|
||||
go_mod_cache=$(go env GOMODCACHE 2> /dev/null || echo "$HOME/go/pkg/mod")
|
||||
|
||||
# Check if Go caches are whitelisted
|
||||
local build_protected=false
|
||||
local mod_protected=false
|
||||
local build_protected=false mod_protected=false
|
||||
is_path_whitelisted "$go_build_cache" && build_protected=true
|
||||
is_path_whitelisted "$go_mod_cache" && mod_protected=true
|
||||
|
||||
if is_path_whitelisted "$go_build_cache"; then
|
||||
build_protected=true
|
||||
fi
|
||||
|
||||
if is_path_whitelisted "$go_mod_cache"; then
|
||||
mod_protected=true
|
||||
fi
|
||||
|
||||
# Only clean if not protected by whitelist
|
||||
if [[ "$build_protected" == "true" && "$mod_protected" == "true" ]]; then
|
||||
if [[ "$DRY_RUN" == "true" ]]; then
|
||||
echo -e " ${YELLOW}${ICON_DRY_RUN}${NC} Go cache · would skip (whitelist)"
|
||||
else
|
||||
echo -e " ${BLUE}${ICON_SKIP}${NC} Go cache · protected by whitelist"
|
||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Go cache · skipped (whitelist)"
|
||||
fi
|
||||
elif [[ "$build_protected" == "true" ]]; then
|
||||
# Only clean module cache
|
||||
clean_tool_cache "Go module cache" bash -c 'go clean -modcache > /dev/null 2>&1 || true'
|
||||
if [[ "$DRY_RUN" != "true" ]]; then
|
||||
echo -e " ${BLUE}${ICON_SKIP}${NC} Go build cache · protected by whitelist"
|
||||
return 0
|
||||
fi
|
||||
note_activity
|
||||
elif [[ "$mod_protected" == "true" ]]; then
|
||||
# Only clean build cache
|
||||
clean_tool_cache "Go build cache" bash -c 'go clean -cache > /dev/null 2>&1 || true'
|
||||
if [[ "$DRY_RUN" != "true" ]]; then
|
||||
echo -e " ${BLUE}${ICON_SKIP}${NC} Go module cache · protected by whitelist"
|
||||
fi
|
||||
note_activity
|
||||
else
|
||||
# Clean both caches
|
||||
|
||||
if [[ "$build_protected" != "true" && "$mod_protected" != "true" ]]; then
|
||||
clean_tool_cache "Go cache" bash -c 'go clean -modcache > /dev/null 2>&1 || true; go clean -cache > /dev/null 2>&1 || true'
|
||||
elif [[ "$build_protected" == "true" ]]; then
|
||||
clean_tool_cache "Go module cache" bash -c 'go clean -modcache > /dev/null 2>&1 || true'
|
||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Go build cache · skipped (whitelist)"
|
||||
else
|
||||
clean_tool_cache "Go build cache" bash -c 'go clean -cache > /dev/null 2>&1 || true'
|
||||
echo -e " ${GREEN}${ICON_SUCCESS}${NC} Go module cache · skipped (whitelist)"
|
||||
fi
|
||||
note_activity
|
||||
fi
|
||||
fi
|
||||
}
|
||||
# Rust/cargo caches.
|
||||
clean_dev_rust() {
|
||||
|
||||
Reference in New Issue
Block a user