From 3232b553acbdf97c4440601ea77b3078514d65ae Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 9 Apr 2026 21:18:59 +0400 Subject: [PATCH] miaou-destroy --- lib/miaou.completion | 10 +++++++ tools/miaou-destroy | 66 ++++++++++++++++++++++++++++++++++++++++++++ tools/miaou-stop | 1 - 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100755 tools/miaou-destroy diff --git a/lib/miaou.completion b/lib/miaou.completion index ec3c7b5..676fccb 100644 --- a/lib/miaou.completion +++ b/lib/miaou.completion @@ -218,8 +218,18 @@ function _miaou_stop { _array_subtract suggestions previous_containers COMPREPLY } +function _miaou_destroy { + local cur="${COMP_WORDS[COMP_CWORD]}" + + # containers... + local suggestions=($(compgen -W "--yes --force $(_incus_running_container)" -- "$cur")) + local previous_containers=("${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}") # drop first and last items + _array_subtract suggestions previous_containers COMPREPLY +} + complete -F _miaou_login "miaou-login" complete -F _miaou_exec "miaou-exec" complete -F _miaou_ls "miaou-ls" complete -F _miaou_start "miaou-start" complete -F _miaou_stop "miaou-stop" +complete -F _miaou_destroy "miaou-destroy" diff --git a/tools/miaou-destroy b/tools/miaou-destroy new file mode 100755 index 0000000..5b1fe7e --- /dev/null +++ b/tools/miaou-destroy @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +# CONSTANTS + +BASEDIR=$(dirname "$0") +CONTAINERS=() +YES=false +FORCE=false + +# FUNCTIONS + +function usage { + echo "$(basename "$0") ... [--yes|-y] [--force|-f]" +} + +function parse_options { + while [[ $# -gt 0 ]]; do + case "$1" in + --help | -h) + usage && exit 0 + ;; + --yes | -y) + YES=true + ;; + --force | -f) + FORCE=true + ;; + -*) + echo >&2 "Error: unknown option: $1" && usage && exit 2 + ;; + *) + CONTAINERS+=("$1") + ;; + esac + + shift 1 # Move to the next argument + done + + [[ ${#CONTAINERS[@]} == 0 ]] && usage && exit 1 || true +} + +function confirm_destructive { + local message="${1:-This cannot be undone!}" + echo "⚠️ WARNING: $message" + read -p "Type YES to confirm: " response + case "$response" in + [yY][eE][sS] | [yY]) return 0 ;; + *) echo "canceled!" && return 1 ;; + esac +} + +function force_option { + [[ $FORCE == false ]] && return + echo '--force ' +} + +function destroy { + [[ $YES == false ]] && confirm_destructive "you are about to destroy ${#CONTAINERS[@]} containers <${CONTAINERS[*]}>" $(force_option) + incus delete "${CONTAINERS[@]}" $(force_option) +} + +# MAIN + +set -Eue +parse_options $* +destroy diff --git a/tools/miaou-stop b/tools/miaou-stop index 6519cba..add611c 100755 --- a/tools/miaou-stop +++ b/tools/miaou-stop @@ -4,7 +4,6 @@ BASEDIR=$(dirname "$0") CONTAINERS=() -USER= # FUNCTIONS