feat: add --yes support to teardown scripts
This commit is contained in:
@@ -10,6 +10,39 @@ set -euo pipefail
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
source "${SCRIPT_DIR}/lib/common.sh"
|
||||
|
||||
# Parse arguments
|
||||
AUTO_YES=false
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--yes|-y) AUTO_YES=true ;;
|
||||
--help|-h)
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") [options]
|
||||
|
||||
Options:
|
||||
--yes, -y Skip all confirmation prompts
|
||||
--help, -h Show this help
|
||||
EOF
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown argument: $arg"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
confirm_action() {
|
||||
local prompt="$1"
|
||||
if [[ "$AUTO_YES" == "true" ]]; then
|
||||
log_info "Auto-confirmed (--yes): ${prompt}"
|
||||
return 0
|
||||
fi
|
||||
printf '%s' "$prompt"
|
||||
read -r confirm
|
||||
[[ "$confirm" =~ ^[Yy]$ ]]
|
||||
}
|
||||
|
||||
load_env
|
||||
require_vars GITEA_ADMIN_TOKEN GITEA_INTERNAL_URL GITEA_ORG_NAME \
|
||||
GITEA_ADMIN_USER \
|
||||
@@ -51,9 +84,7 @@ git_with_auth() {
|
||||
"$@"
|
||||
}
|
||||
|
||||
printf 'This will remove .gitea/workflows/ from all repos. Continue? [y/N] '
|
||||
read -r confirm
|
||||
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
||||
if ! confirm_action 'This will remove .gitea/workflows/ from all repos. Continue? [y/N] '; then
|
||||
log_info "Teardown cancelled"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user