incubator-airflow/confirm

52 строки
1.6 KiB
Plaintext
Исходник Обычный вид История

#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
set -euo pipefail
Implement Google Shell Conventions for breeze script (#10695) * Implement Google Shell Conventions for breeze script … (#10651) Part of #10576 First (and the biggest of the series of commits to introduce Google Shell Conventions in our bash scripts. This is about the biggest and the most complex breeze script so it is rather huge but it is difficult to split it into smaller pieces. The rules implemented (from the conventions): * constants and exported variables are CAPITALIZED, where local/temporary variables are lowercase * following the shell guide, once all the variables are set to their final values (either from exported variables, calculation or --switches ) I have a single function that makes all the variables read-only. That helped to clean-up a lot of places where same functions was called several times, or where variables were defined in a few places. Now the behavior should be rather consistent and we should easily catch some duplications * function headers (following the guide) explaining arguments, variables expected, variables modified in the functions used. * setting the variables as read-only also helped to clean-up the "ifs" where we often had ":=}" in variables and != "" or == "". Those are replaced with `=}` and tests are replaced with `-n` and `-z` - also following the shell guide (readonly helped to detect and clean all such cases). This also should be much more robust in the future. * reorganized initialization of those constants and variables - simplified a few places where initialization was overlapping. It should be much more straightforward and clean now * a number of internal function breeze variables are "local" - this is helpful in accidental variables overwriting and keeping stuff localized * trap_add function is separated out to help in cases where we had several traps handling the same signals. (cherry picked from commit 46c8d6714c981746cc114b8b1af5cb27aa0018e2) (cherry picked from commit c822fd7b4bf2a9c5a9bb3c6e783cbea9dac37246) * fixup! Implement Google Shell Conventions for breeze script … (#10651)
2020-09-02 22:55:50 +03:00
if [[ -n "${FORCE_ANSWER_TO_QUESTIONS=}" ]]; then
RESPONSE=${FORCE_ANSWER_TO_QUESTIONS}
echo
echo "Forcing response '${FORCE_ANSWER_TO_QUESTIONS}' to '${1}?'"
case "${RESPONSE}" in
[yY][eE][sS]|[yY])
exit 0 ;;
[qQ][uU][iI][tT]|[qQ])
exit 2 ;;
*)
exit 1 ;;
esac
else
echo
echo "Please confirm ${1}. Are you sure? [y/N/q]"
read -r RESPONSE
fi
case "${RESPONSE}" in
[yY][eE][sS]|[yY])
echo "The answer is 'yes'. ${1}. This can take some time!"
exit 0
;;
[qQ][uU][iI][tT]|[qQ])
echo "The answer is 'quit'. Quitting now!"
exit 2
;;
*)
echo "The answer is 'no'. Skipping ${1}."
exit 1
;;
esac