Improve readability

This commit is contained in:
Nathaniel Landau
2021-09-11 10:15:23 -04:00
parent e014a1dc2a
commit 3c490fa710

View File

@@ -231,7 +231,7 @@ _safeExit_() {
# ARGS: $1 (optional) - Exit code (defaults to 0) # ARGS: $1 (optional) - Exit code (defaults to 0)
# OUTS: None # OUTS: None
if [[ -d "${SCRIPT_LOCK:-}" ]]; then if [[ -d ${SCRIPT_LOCK:-} ]]; then
if command rm -rf "${SCRIPT_LOCK}"; then if command rm -rf "${SCRIPT_LOCK}"; then
debug "Removing script lock" debug "Removing script lock"
else else
@@ -239,7 +239,7 @@ _safeExit_() {
fi fi
fi fi
if [[ -n "${TMP_DIR:-}" && -d "${TMP_DIR:-}" ]]; then if [[ -n ${TMP_DIR:-} && -d ${TMP_DIR:-} ]]; then
if [[ ${1:-} == 1 && -n "$(ls "${TMP_DIR}")" ]]; then if [[ ${1:-} == 1 && -n "$(ls "${TMP_DIR}")" ]]; then
# Do something here to save TMP_DIR on a non-zero script exit for debugging # Do something here to save TMP_DIR on a non-zero script exit for debugging
command rm -r "${TMP_DIR}" command rm -r "${TMP_DIR}"
@@ -273,7 +273,7 @@ _trapCleanup_() {
funcstack="'$(echo "$funcstack" | sed -E 's/ / < /g')'" funcstack="'$(echo "$funcstack" | sed -E 's/ / < /g')'"
if [[ "${script##*/}" == "${sourced##*/}" ]]; then if [[ ${script##*/} == "${sourced##*/}" ]]; then
fatal "${7:-} command: '${command}' (line: ${line}) [func: $(_functionStack_)]" fatal "${7:-} command: '${command}' (line: ${line}) [func: $(_functionStack_)]"
else else
fatal "${7:-} command: '${command}' (func: ${funcstack} called at line ${linecallfunc} of '${script##*/}') (line: $line of '${sourced##*/}') " fatal "${7:-} command: '${command}' (func: ${funcstack} called at line ${linecallfunc} of '${script##*/}') (line: $line of '${sourced##*/}') "
@@ -335,7 +335,7 @@ _functionStack_() {
funcStackResponse=() funcStackResponse=()
for ((_i = 1; _i < ${#BASH_SOURCE[@]}; _i++)); do for ((_i = 1; _i < ${#BASH_SOURCE[@]}; _i++)); do
case "${FUNCNAME[$_i]}" in "_alert_" | "_trapCleanup_" | fatal | error | warning | notice | info | verbose | debug | dryrun | header | success | die) continue ;; esac case "${FUNCNAME[$_i]}" in "_alert_" | "_trapCleanup_" | fatal | error | warning | notice | info | verbose | debug | dryrun | header | success | die) continue ;; esac
funcStackResponse+=("${FUNCNAME[$_i]}:$(basename ${BASH_SOURCE[$_i]}):${BASH_LINENO[$_i - 1]}") funcStackResponse+=("${FUNCNAME[$_i]}:$(basename ${BASH_SOURCE[$_i]}):${BASH_LINENO[_i - 1]}")
done done
printf "( " printf "( "
printf %s "${funcStackResponse[0]}" printf %s "${funcStackResponse[0]}"
@@ -435,19 +435,46 @@ EOF
# ################################## INITIALIZE AND RUN THE SCRIPT # ################################## INITIALIZE AND RUN THE SCRIPT
# (Comment or uncomment the lines below to customize script behavior) # (Comment or uncomment the lines below to customize script behavior)
trap '_trapCleanup_ ${LINENO} ${BASH_LINENO} "${BASH_COMMAND}" "${FUNCNAME[*]}" "${0}" "${BASH_SOURCE[0]}"' \ trap '_trapCleanup_ ${LINENO} ${BASH_LINENO} "${BASH_COMMAND}" "${FUNCNAME[*]}" "${0}" "${BASH_SOURCE[0]}"' EXIT INT TERM SIGINT SIGQUIT
EXIT INT TERM SIGINT SIGQUIT
set -o errtrace # Trap errors in subshells and functions # Trap errors in subshells and functions
set -o errexit # Exit on error. Append '||true' if you expect an error set -o errtrace
set -o pipefail # Use last non-zero exit code in a pipeline
# shopt -s nullglob globstar # Make `for f in *.txt` work when `*.txt` matches zero files # Exit on error. Append '||true' if you expect an error
IFS=$' \n\t' # Set IFS to preferred implementation set -o errexit
# set -o xtrace # Run in debug mode
_setColors_ # Initialize color constants # Use last non-zero exit code in a pipeline
set -o nounset # Disallow expansion of unset variables set -o pipefail
# [[ $# -eq 0 ]] && _parseOptions_ "-h" # Force arguments when invoking the script
_parseOptions_ "$@" # Parse arguments passed to script # Make `for f in *.txt` work when `*.txt` matches zero files
# _makeTempDir_ "$(basename "$0")" # Create a temp directory '$TMP_DIR' # shopt -s nullglob globstar
# _acquireScriptLock_ # Acquire script lock
_mainScript_ # Run the main logic script # Set IFS to preferred implementation
_safeExit_ # Exit cleanly IFS=$' \n\t'
# Run in debug mode
# set -o xtrace
# Initialize color constants
_setColors_
# Disallow expansion of unset variables
set -o nounset
# Force arguments when invoking the script
# [[ $# -eq 0 ]] && _parseOptions_ "-h"
# Parse arguments passed to script
_parseOptions_ "$@"
# Create a temp directory '$TMP_DIR'
# _makeTempDir_ "$(basename "$0")"
# Acquire script lock
# _acquireScriptLock_
# Run the main logic script
_mainScript_
# Exit cleanly
_safeExit_