Skip to content

Commit

Permalink
Added errorX function, which exits with non-zero value after execution
Browse files Browse the repository at this point in the history
Added BITNAMI_COLOR method, which can control the color switch
Signed-off-by: huangjc7 <[email protected]>
  • Loading branch information
huangjc7 committed Jan 29, 2025
1 parent 6b00154 commit cb6719d
Showing 1 changed file with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ stderr_print() {
local bool="${BITNAMI_QUIET:-false}"
# comparison is performed without regard to the case of alphabetic characters
shopt -s nocasematch
if ! [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]]; then
printf "%b\\n" "${*}" >&2
fi
! [[ "$bool" = 1 || "$bool" =~ ^(yes|true)$ ]] && printf "%b\\n" "${*}" >&2

}

########################
Expand All @@ -42,7 +41,7 @@ log() {
local prefix=""
local suffix=""
local color_bool="${BITNAMI_COLOR:-true}"
if [[ "$color_bool" =~ ^(yes|true)$ ]]; then
if [[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]]; then
prefix="${CYAN}${MODULE:-} ${MAGENTA}$(date "+%T.%2N ")${RESET}"
suffix="${RESET}"
else
Expand All @@ -61,7 +60,7 @@ info() {
local msg_color=""
local reset_color="$RESET"
local color_bool="${BITNAMI_COLOR:-true}"
[[ "$color_bool" =~ ^(yes|true)$ ]] && msg_color="$GREEN"
[[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]] && msg_color="$GREEN"
log "${msg_color}INFO ${reset_color} ==> ${*}"
}
########################
Expand All @@ -75,7 +74,7 @@ warn() {
local msg_color=""
local reset_color="$RESET"
local color_bool="${BITNAMI_COLOR:-true}"
[[ "$color_bool" =~ ^(yes|true)$ ]] && msg_color="$YELLOW"
[[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]] && msg_color="$YELLOW"
log "${msg_color}WARN ${reset_color} ==> ${*}"
}
########################
Expand All @@ -89,11 +88,11 @@ error() {
local msg_color=""
local reset_color="$RESET"
local color_bool="${BITNAMI_COLOR:-true}"
[[ "$color_bool" =~ ^(yes|true)$ ]] && msg_color="$RED"
[[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]] && msg_color="$RED"
log "${msg_color}ERROR${reset_color} ==> ${*}"
}
########################
# Log an 'errorX' message
# Log an "error" message and exit with non-zero value
# Arguments:
# Message to log
# Returns:
Expand All @@ -103,7 +102,7 @@ errorX() {
local msg_color=""
local reset_color="$RESET"
local color_bool="${BITNAMI_COLOR:-true}"
[[ "$color_bool" =~ ^(yes|true)$ ]] && msg_color="$RED"
[[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]] && msg_color="$RED"
log "${msg_color}ERROR${reset_color} ==> ${*}"
exit 1
}
Expand All @@ -120,7 +119,7 @@ debug() {
local msg_color=""
local reset_color="$RESET"
local color_bool="${BITNAMI_COLOR:-true}"
[[ "$color_bool" =~ ^(yes|true)$ ]] && msg_color="$MAGENTA"
[[ "$color_bool" = 1 || "$color_bool" =~ ^(yes|true)$ ]] && msg_color="$MAGENTA"
# comparison is performed without regard to the case of alphabetic characters
shopt -s nocasematch
local debug_bool="${BITNAMI_DEBUG:-false}"
Expand Down Expand Up @@ -149,4 +148,4 @@ indent() {
# shellcheck disable=SC2001
# Complex regex, see https://github.com/koalaman/shellcheck/wiki/SC2001#exceptions
echo "$string" | sed "s/^/${indent_unit}/"
}
}

0 comments on commit cb6719d

Please sign in to comment.