Make --no-prompt more consistent

This commit is contained in:
3wc 2021-04-07 20:44:41 +02:00
parent 968d3809a5
commit 523fc2850c

43
abra
View File

@ -672,7 +672,6 @@ output_version_summary() {
echo " Versions:" echo " Versions:"
CONSENT_TO_UPDATE=$abra___update CONSENT_TO_UPDATE=$abra___update
NON_INTERACTIVE=$abra___no_prompt
FORCE_DEPLOY=$abra___force FORCE_DEPLOY=$abra___force
local -a IS_AN_UPDATE="false" local -a IS_AN_UPDATE="false"
@ -735,11 +734,10 @@ output_version_summary() {
exit 0 exit 0
fi fi
if [[ $IS_AN_UPDATE == "true" ]] && [[ $NON_INTERACTIVE == "false" ]]; then if [[ $IS_AN_UPDATE == "true" ]]; then
require_consent_for_update require_consent_for_update
else else
if [[ $UNABLE_TO_DETECT == "false" ]] && \ if [[ $UNABLE_TO_DETECT == "false" ]] && \
[[ $NON_INTERACTIVE == "false" ]] && \
[[ $UNDEPLOYED_STATE == "false" ]] && \ [[ $UNDEPLOYED_STATE == "false" ]] && \
[[ $FORCE_DEPLOY == "false" ]]; then [[ $FORCE_DEPLOY == "false" ]]; then
success "Nothing to deploy, you're on latest (use --force to re-deploy anyway)" success "Nothing to deploy, you're on latest (use --force to re-deploy anyway)"
@ -878,6 +876,10 @@ load_context() {
} }
prompt_confirm() { prompt_confirm() {
if [ "$abra___no_prompt" = "true" ]; then
return
fi
read -rp "Continue? (y/[n])? " choice read -rp "Continue? (y/[n])? " choice
case "$choice" in case "$choice" in
@ -1085,8 +1087,10 @@ sub_app_new (){
get_recipe_versions "$TYPE" get_recipe_versions "$TYPE"
if [ "${#RECIPE_VERSIONS[@]}" = 0 ]; then if [ "${#RECIPE_VERSIONS[@]}" = 0 ]; then
VERSION="" VERSION=""
warning "No version specified, dangerously using latest git 😨"
else else
VERSION="${RECIPE_VERSIONS[-1]}" VERSION="${RECIPE_VERSIONS[-1]}"
info "Chose version $VERSION"
fi fi
require_app_version "$TYPE" "$VERSION" require_app_version "$TYPE" "$VERSION"
@ -1153,6 +1157,8 @@ sub_app_new (){
if [ "${#PASSWORDS[@]}" -eq 0 ]; then if [ "${#PASSWORDS[@]}" -eq 0 ]; then
warning "--secrets provided but no secrets found" warning "--secrets provided but no secrets found"
fi fi
load_instance
load_instance_env
auto_gen_secrets auto_gen_secrets
fi fi
@ -1276,7 +1282,6 @@ POWERED BY
sub_app_deploy (){ sub_app_deploy (){
require_yq require_yq
NON_INTERACTIVE=$abra___no_prompt
SKIP_VERSION_CHECK=$abra___skip_version_check SKIP_VERSION_CHECK=$abra___skip_version_check
NO_DOMAIN_POLL=$abra___no_domain_poll NO_DOMAIN_POLL=$abra___no_domain_poll
@ -1318,9 +1323,7 @@ sub_app_deploy (){
output_version_summary output_version_summary
fi fi
if [[ $NON_INTERACTIVE == "false" ]]; then prompt_confirm
prompt_confirm
fi
APP=$(basename "$APP_DIR") APP=$(basename "$APP_DIR")
@ -1355,14 +1358,8 @@ POWERED BY
} }
sub_app_undeploy (){ sub_app_undeploy (){
NON_INTERACTIVE=$abra___no_prompt
warning "About to un-deploy $STACK_NAME from $SERVER" warning "About to un-deploy $STACK_NAME from $SERVER"
if [[ $NON_INTERACTIVE == "false" ]]; then
prompt_confirm
fi
if ! docker stack ls --format "{{ .Name }}" | grep -q "$STACK_NAME"; then if ! docker stack ls --format "{{ .Name }}" | grep -q "$STACK_NAME"; then
error "$STACK_NAME is already undeployed, nothing to do" error "$STACK_NAME is already undeployed, nothing to do"
fi fi
@ -1492,19 +1489,15 @@ POWERED BY
} }
sub_app_delete (){ sub_app_delete (){
NON_INTERACTIVE=$abra___no_prompt warning "About to delete $ENV_FILE"
prompt_confirm
if [ "$NON_INTERACTIVE" == "false" ]; then
warning "About to delete $ENV_FILE"
prompt_confirm
fi
rm "$ENV_FILE" rm "$ENV_FILE"
if [ "$abra___volumes" = "true" ]; then if [ "$abra___volumes" = "true" ]; then
volumes="$(docker volume ls --filter "name=${STACK_NAME}" --quiet)" volumes="$(docker volume ls --filter "name=${STACK_NAME}" --quiet)"
if [ "$NON_INTERACTIVE" == "false" ] && [ "$abra___volumes" = "true" ]; then if [ "$abra___volumes" = "true" ]; then
# shellcheck disable=SC2086 # shellcheck disable=SC2086
warning "SCARY: About to remove all volumes associated with ${STACK_NAME}: $(echo $volumes | tr -d '\n')" warning "SCARY: About to remove all volumes associated with ${STACK_NAME}: $(echo $volumes | tr -d '\n')"
@ -1518,7 +1511,7 @@ sub_app_delete (){
if [ "$abra___secrets" = "true" ]; then if [ "$abra___secrets" = "true" ]; then
secrets="$(docker secret ls --filter "name=${STACK_NAME}" --quiet)" secrets="$(docker secret ls --filter "name=${STACK_NAME}" --quiet)"
if [ "$NON_INTERACTIVE" == "false" ] && [ "$abra___secrets" = "true" ]; then if [ "$abra___secrets" = "true" ]; then
# shellcheck disable=SC2086 # shellcheck disable=SC2086
warning "SCARY: About to remove all secrets associated with ${STACK_NAME}: $(echo $secrets | tr -d '\n')" warning "SCARY: About to remove all secrets associated with ${STACK_NAME}: $(echo $secrets | tr -d '\n')"
@ -1584,8 +1577,6 @@ POWERED BY
} }
sub_app_secret_delete(){ sub_app_secret_delete(){
NON_INTERACTIVE=$abra___no_prompt
# if --all is provided then $abra__secret_ will be blank and this will work # if --all is provided then $abra__secret_ will be blank and this will work
# auto-magically # auto-magically
NAMES=$(docker secret ls --filter "name=${STACK_NAME}_${abra__secret_}" --format "{{.Name}}") NAMES=$(docker secret ls --filter "name=${STACK_NAME}_${abra__secret_}" --format "{{.Name}}")
@ -1594,10 +1585,8 @@ sub_app_secret_delete(){
error "Could not find any secrets under ${STACK_NAME}_${abra__secret_}" error "Could not find any secrets under ${STACK_NAME}_${abra__secret_}"
fi fi
if [ "$NON_INTERACTIVE" == "false" ]; then warning "About to delete $(echo "$NAMES" | paste -d "")"
warning "About to delete $(echo "$NAMES" | paste -d "")" prompt_confirm
prompt_confirm
fi
for NAME in ${NAMES}; do for NAME in ${NAMES}; do
docker secret rm "$NAME" > /dev/null docker secret rm "$NAME" > /dev/null