mirror of
https://github.com/tw93/Mole.git
synced 2026-03-24 12:20:06 +00:00
refactor(dry-run): unify flag handling in completion and remove
This commit is contained in:
@@ -32,13 +32,12 @@ emit_fish_completions() {
|
|||||||
printf 'complete -c %s -n "not __fish_mole_no_subcommand" -a fish -d "generate fish completion" -n "__fish_see_subcommand_path completion"\n' "$cmd"
|
printf 'complete -c %s -n "not __fish_mole_no_subcommand" -a fish -d "generate fish completion" -n "__fish_see_subcommand_path completion"\n' "$cmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
DRY_RUN_MODE=false
|
|
||||||
if [[ $# -gt 0 ]]; then
|
if [[ $# -gt 0 ]]; then
|
||||||
normalized_args=()
|
normalized_args=()
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
"--dry-run" | "-n")
|
"--dry-run" | "-n")
|
||||||
DRY_RUN_MODE=true
|
export MOLE_DRY_RUN=1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
normalized_args+=("$arg")
|
normalized_args+=("$arg")
|
||||||
@@ -54,7 +53,7 @@ fi
|
|||||||
|
|
||||||
# Auto-install mode when run without arguments
|
# Auto-install mode when run without arguments
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -eq 0 ]]; then
|
||||||
if [[ "$DRY_RUN_MODE" == "true" ]]; then
|
if [[ "${MOLE_DRY_RUN:-0}" == "1" ]]; then
|
||||||
echo -e "${YELLOW}${ICON_DRY_RUN} DRY RUN MODE${NC}, shell config files will not be modified"
|
echo -e "${YELLOW}${ICON_DRY_RUN} DRY RUN MODE${NC}, shell config files will not be modified"
|
||||||
echo ""
|
echo ""
|
||||||
fi
|
fi
|
||||||
@@ -98,7 +97,7 @@ if [[ $# -eq 0 ]]; then
|
|||||||
|
|
||||||
if [[ -z "$completion_name" ]]; then
|
if [[ -z "$completion_name" ]]; then
|
||||||
if [[ -f "$config_file" ]] && grep -Eq "(^# Mole shell completion$|(mole|mo)[[:space:]]+completion)" "$config_file" 2> /dev/null; then
|
if [[ -f "$config_file" ]] && grep -Eq "(^# Mole shell completion$|(mole|mo)[[:space:]]+completion)" "$config_file" 2> /dev/null; then
|
||||||
if [[ "$DRY_RUN_MODE" == "true" ]]; then
|
if [[ "${MOLE_DRY_RUN:-0}" == "1" ]]; then
|
||||||
echo -e "${GRAY}${ICON_REVIEW} [DRY RUN] Would remove stale completion entries from $config_file${NC}"
|
echo -e "${GRAY}${ICON_REVIEW} [DRY RUN] Would remove stale completion entries from $config_file${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
else
|
else
|
||||||
@@ -120,7 +119,7 @@ if [[ $# -eq 0 ]]; then
|
|||||||
|
|
||||||
# Check if already installed and normalize to latest line
|
# Check if already installed and normalize to latest line
|
||||||
if [[ -f "$config_file" ]] && grep -Eq "(mole|mo)[[:space:]]+completion" "$config_file" 2> /dev/null; then
|
if [[ -f "$config_file" ]] && grep -Eq "(mole|mo)[[:space:]]+completion" "$config_file" 2> /dev/null; then
|
||||||
if [[ "$DRY_RUN_MODE" == "true" ]]; then
|
if [[ "${MOLE_DRY_RUN:-0}" == "1" ]]; then
|
||||||
echo -e "${GRAY}${ICON_REVIEW} [DRY RUN] Would normalize completion entry in $config_file${NC}"
|
echo -e "${GRAY}${ICON_REVIEW} [DRY RUN] Would normalize completion entry in $config_file${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
exit 0
|
exit 0
|
||||||
@@ -150,7 +149,7 @@ if [[ $# -eq 0 ]]; then
|
|||||||
echo -e "${GRAY}Will add to ${config_file}:${NC}"
|
echo -e "${GRAY}Will add to ${config_file}:${NC}"
|
||||||
echo " $completion_line"
|
echo " $completion_line"
|
||||||
echo ""
|
echo ""
|
||||||
if [[ "$DRY_RUN_MODE" == "true" ]]; then
|
if [[ "${MOLE_DRY_RUN:-0}" == "1" ]]; then
|
||||||
echo -e "${GREEN}${ICON_SUCCESS}${NC} Dry run complete, no changes made"
|
echo -e "${GREEN}${ICON_SUCCESS}${NC} Dry run complete, no changes made"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
50
mole
50
mole
@@ -553,6 +553,31 @@ remove_mole() {
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Dry-run mode: show preview and exit without confirmation
|
||||||
|
if [[ "$dry_run_mode" == "true" ]]; then
|
||||||
|
echo -e "${YELLOW}${ICON_DRY_RUN} DRY RUN MODE${NC}, no files will be removed"
|
||||||
|
echo ""
|
||||||
|
echo -e "${YELLOW}Remove Mole${NC}, would delete the following:"
|
||||||
|
if [[ "$is_homebrew" == "true" ]]; then
|
||||||
|
echo -e " ${GRAY}${ICON_LIST} Would run: brew uninstall --force mole${NC}"
|
||||||
|
fi
|
||||||
|
if [[ ${manual_count:-0} -gt 0 ]]; then
|
||||||
|
for install in "${manual_installs[@]}"; do
|
||||||
|
[[ -f "$install" ]] && echo -e " ${GRAY}${ICON_LIST} Would remove: ${install}${NC}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if [[ ${alias_count:-0} -gt 0 ]]; then
|
||||||
|
for alias in "${alias_installs[@]}"; do
|
||||||
|
[[ -f "$alias" ]] && echo -e " ${GRAY}${ICON_LIST} Would remove: ${alias}${NC}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
[[ -d "$HOME/.cache/mole" ]] && echo -e " ${GRAY}${ICON_LIST} Would remove: $HOME/.cache/mole${NC}"
|
||||||
|
[[ -d "$HOME/.config/mole" ]] && echo -e " ${GRAY}${ICON_LIST} Would remove: $HOME/.config/mole${NC}"
|
||||||
|
|
||||||
|
printf '\n%s\n\n' "${GREEN}${ICON_SUCCESS}${NC} Dry run complete, no changes made"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
echo -e "${YELLOW}Remove Mole${NC}, will delete the following:"
|
echo -e "${YELLOW}Remove Mole${NC}, will delete the following:"
|
||||||
if [[ "$is_homebrew" == "true" ]]; then
|
if [[ "$is_homebrew" == "true" ]]; then
|
||||||
echo " ${ICON_LIST} Mole via Homebrew"
|
echo " ${ICON_LIST} Mole via Homebrew"
|
||||||
@@ -579,31 +604,6 @@ remove_mole() {
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
local has_error=false
|
local has_error=false
|
||||||
if [[ "$dry_run_mode" == "true" ]]; then
|
|
||||||
echo ""
|
|
||||||
echo -e "${YELLOW}${ICON_DRY_RUN} DRY RUN MODE${NC}, no files will be removed"
|
|
||||||
|
|
||||||
if [[ "$is_homebrew" == "true" ]]; then
|
|
||||||
echo -e " ${GRAY}${ICON_LIST} Would run: brew uninstall --force mole${NC}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${manual_count:-0} -gt 0 ]]; then
|
|
||||||
for install in "${manual_installs[@]}"; do
|
|
||||||
[[ -f "$install" ]] && echo -e " ${GRAY}${ICON_LIST} Would remove: ${install}${NC}"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
if [[ ${alias_count:-0} -gt 0 ]]; then
|
|
||||||
for alias in "${alias_installs[@]}"; do
|
|
||||||
[[ -f "$alias" ]] && echo -e " ${GRAY}${ICON_LIST} Would remove: ${alias}${NC}"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
[[ -d "$HOME/.cache/mole" ]] && echo -e " ${GRAY}${ICON_LIST} Would remove: $HOME/.cache/mole${NC}"
|
|
||||||
[[ -d "$HOME/.config/mole" ]] && echo -e " ${GRAY}${ICON_LIST} Would remove: $HOME/.config/mole${NC}"
|
|
||||||
|
|
||||||
printf '\n%s\n\n' "${GREEN}${ICON_SUCCESS}${NC} Dry run complete, no changes made"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$is_homebrew" == "true" ]]; then
|
if [[ "$is_homebrew" == "true" ]]; then
|
||||||
if [[ -z "$brew_cmd" ]]; then
|
if [[ -z "$brew_cmd" ]]; then
|
||||||
log_error "Homebrew command not found. Please ensure Homebrew is installed and in your PATH."
|
log_error "Homebrew command not found. Please ensure Homebrew is installed and in your PATH."
|
||||||
|
|||||||
Reference in New Issue
Block a user