Browse Source

miaou-destroy

main
pvincent 3 weeks ago
parent
commit
3232b553ac
  1. 10
      lib/miaou.completion
  2. 66
      tools/miaou-destroy
  3. 1
      tools/miaou-stop

10
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"

66
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") <CONTAINER_NAME>... [--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

1
tools/miaou-stop

@ -4,7 +4,6 @@
BASEDIR=$(dirname "$0")
CONTAINERS=()
USER=
# FUNCTIONS

Loading…
Cancel
Save