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:"
CONSENT_TO_UPDATE=$abra___update
NON_INTERACTIVE=$abra___no_prompt
FORCE_DEPLOY=$abra___force
local -a IS_AN_UPDATE="false"
@ -735,11 +734,10 @@ output_version_summary() {
exit 0
fi
if [[ $IS_AN_UPDATE == "true" ]] && [[ $NON_INTERACTIVE == "false" ]]; then
if [[ $IS_AN_UPDATE == "true" ]]; then
require_consent_for_update
else
if [[ $UNABLE_TO_DETECT == "false" ]] && \
[[ $NON_INTERACTIVE == "false" ]] && \
[[ $UNDEPLOYED_STATE == "false" ]] && \
[[ $FORCE_DEPLOY == "false" ]]; then
success "Nothing to deploy, you're on latest (use --force to re-deploy anyway)"
@ -878,6 +876,10 @@ load_context() {
}
prompt_confirm() {
if [ "$abra___no_prompt" = "true" ]; then
return
fi
read -rp "Continue? (y/[n])? " choice
case "$choice" in
@ -1085,8 +1087,10 @@ sub_app_new (){
get_recipe_versions "$TYPE"
if [ "${#RECIPE_VERSIONS[@]}" = 0 ]; then
VERSION=""
warning "No version specified, dangerously using latest git 😨"
else
VERSION="${RECIPE_VERSIONS[-1]}"
info "Chose version $VERSION"
fi
require_app_version "$TYPE" "$VERSION"
@ -1153,6 +1157,8 @@ sub_app_new (){
if [ "${#PASSWORDS[@]}" -eq 0 ]; then
warning "--secrets provided but no secrets found"
fi
load_instance
load_instance_env
auto_gen_secrets
fi
@ -1276,7 +1282,6 @@ POWERED BY
sub_app_deploy (){
require_yq
NON_INTERACTIVE=$abra___no_prompt
SKIP_VERSION_CHECK=$abra___skip_version_check
NO_DOMAIN_POLL=$abra___no_domain_poll
@ -1318,9 +1323,7 @@ sub_app_deploy (){
output_version_summary
fi
if [[ $NON_INTERACTIVE == "false" ]]; then
prompt_confirm
fi
prompt_confirm
APP=$(basename "$APP_DIR")
@ -1355,14 +1358,8 @@ POWERED BY
}
sub_app_undeploy (){
NON_INTERACTIVE=$abra___no_prompt
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
error "$STACK_NAME is already undeployed, nothing to do"
fi
@ -1492,19 +1489,15 @@ POWERED BY
}
sub_app_delete (){
NON_INTERACTIVE=$abra___no_prompt
if [ "$NON_INTERACTIVE" == "false" ]; then
warning "About to delete $ENV_FILE"
prompt_confirm
fi
warning "About to delete $ENV_FILE"
prompt_confirm
rm "$ENV_FILE"
if [ "$abra___volumes" = "true" ]; then
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
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
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
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(){
NON_INTERACTIVE=$abra___no_prompt
# if --all is provided then $abra__secret_ will be blank and this will work
# auto-magically
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_}"
fi
if [ "$NON_INTERACTIVE" == "false" ]; then
warning "About to delete $(echo "$NAMES" | paste -d "")"
prompt_confirm
fi
warning "About to delete $(echo "$NAMES" | paste -d "")"
prompt_confirm
for NAME in ${NAMES}; do
docker secret rm "$NAME" > /dev/null