From abfdcaae36eaf8944a277089d7977a4c217751c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Chastanet?= Date: Sat, 6 Jan 2024 10:32:28 +0100 Subject: [PATCH] Better configuration loading management. Short 3 lines summary tag: 2.2.0 # Breaking changes # Bug fixes - fixed regression - global options passed to the command was not taken into account(--verbose, -no-color, --log-level, ...) # Compiler changes # Binaries changes - all binaries are using - shopt -s lastpipe headers change # Updated Bash framework functions # New Bash framework functions # Documentation # Validation/Tooling --- bin/awkLint | 75 ++++++++++++++-------- bin/buildBinFiles | 75 ++++++++++++++-------- bin/buildPushDockerImage | 81 ++++++++++++++--------- bin/definitionLint | 77 +++++++++++++--------- bin/doc | 89 +++++++++++++++----------- bin/dockerLint | 67 +++++++++++-------- bin/findShebangFiles | 75 ++++++++++++++-------- bin/frameworkLint | 77 +++++++++++++--------- bin/installFacadeExample | 12 ++-- bin/megalinter | 81 ++++++++++++++--------- bin/plantuml | 67 +++++++++++-------- bin/runBuildContainer | 81 ++++++++++++++--------- bin/shellcheckLint | 69 +++++++++++--------- bin/test | 73 ++++++++++++--------- src/Env/requireLoad.sh | 4 -- src/_binaries/options/options.base.tpl | 41 +++++++----- src/_includes/_mandatoryHeader.sh | 8 ++- 17 files changed, 636 insertions(+), 416 deletions(-) diff --git a/bin/awkLint b/bin/awkLint index faee2def..aad81a8a 100755 --- a/bin/awkLint +++ b/bin/awkLint @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -253,10 +259,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -269,6 +271,14 @@ Env::requireLoad() { done } +# @description create a temp file using default TMPDIR variable +# initialized in _includes/_commonHeader.sh +# @env TMPDIR String (default value /tmp) +# @arg $1 templateName:String template name to use(optional) +Framework::createTempFile() { + mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" +} + # @description Log namespace provides 2 kind of functions # - Log::display* allows to display given message with # given display level @@ -716,21 +726,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -739,10 +749,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -763,7 +773,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -785,7 +795,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -795,18 +805,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -873,15 +883,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1086,15 +1105,15 @@ awkLintCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 12/14 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1126,15 +1145,15 @@ awkLintCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 14/14 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1218,7 +1237,7 @@ Result in checkstyle format.")" # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1240,7 +1259,7 @@ Result in checkstyle format.")" # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1251,7 +1270,7 @@ Result in checkstyle format.")" # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo echo -n -e "${__HELP_TITLE_COLOR}VERSION: ${__RESET_COLOR}" echo '1.0' diff --git a/bin/buildBinFiles b/bin/buildBinFiles index e3dff3fb..ab61b579 100755 --- a/bin/buildBinFiles +++ b/bin/buildBinFiles @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -253,10 +259,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -269,6 +271,14 @@ Env::requireLoad() { done } +# @description create a temp file using default TMPDIR variable +# initialized in _includes/_commonHeader.sh +# @env TMPDIR String (default value /tmp) +# @arg $1 templateName:String template name to use(optional) +Framework::createTempFile() { + mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" +} + # @description Log namespace provides 2 kind of functions # - Log::display* allows to display given message with # given display level @@ -716,21 +726,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -739,10 +749,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -763,7 +773,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -785,7 +795,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -795,18 +805,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -873,15 +883,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1102,15 +1121,15 @@ buildBinFilesCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 13/15 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1142,15 +1161,15 @@ buildBinFilesCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 15/15 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1257,7 +1276,7 @@ INTERNAL TOOL")" # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1279,7 +1298,7 @@ INTERNAL TOOL")" # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1290,7 +1309,7 @@ INTERNAL TOOL")" # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo echo -n -e "${__HELP_TITLE_COLOR}VERSION: ${__RESET_COLOR}" echo '1.0' diff --git a/bin/buildPushDockerImage b/bin/buildPushDockerImage index 0be65774..add53a68 100755 --- a/bin/buildPushDockerImage +++ b/bin/buildPushDockerImage @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -314,10 +320,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -330,6 +332,14 @@ Env::requireLoad() { done } +# @description create a temp file using default TMPDIR variable +# initialized in _includes/_commonHeader.sh +# @env TMPDIR String (default value /tmp) +# @arg $1 templateName:String template name to use(optional) +Framework::createTempFile() { + mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" +} + # @description Log namespace provides 2 kind of functions # - Log::display* allows to display given message with # given display level @@ -777,21 +787,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -800,10 +810,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -824,7 +834,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -846,7 +856,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -856,18 +866,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -934,15 +944,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1272,15 +1291,15 @@ buildPushDockerImageCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 17/19 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1312,15 +1331,15 @@ buildPushDockerImageCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 19/19 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1378,21 +1397,21 @@ INTERNAL # shellcheck disable=SC2054 helpArray=(vendor\ image\ to\ use:\ alpine\|ubuntu) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: ubuntu' + echo " Default value: ubuntu" echo ' Possible values: alpine|ubuntu' echo -e " ${__HELP_OPTION_COLOR}--bash-version ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 helpArray=(version\ of\ bash\ to\ use:\ 4.4\|5.0\|5.1\|5.2) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: 5.1' + echo " Default value: 5.1" echo ' Possible values: 4.4|5.0|5.1|5.2' echo -e " ${__HELP_OPTION_COLOR}--bash-base-image ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 helpArray=(bash\ bash\ image\ to\ use\ \(eg:\ ubuntu:20.04\,\ amd64/bash:4.4-alpine3.18\)) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: ubuntu:20.04' + echo " Default value: ubuntu:20.04" echo -e " ${__HELP_OPTION_COLOR}--branch-name ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1445,7 +1464,7 @@ INTERNAL # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1467,7 +1486,7 @@ INTERNAL # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1478,7 +1497,7 @@ INTERNAL # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo echo -n -e "${__HELP_TITLE_COLOR}VERSION: ${__RESET_COLOR}" echo '1.0' diff --git a/bin/definitionLint b/bin/definitionLint index 2dfbfa09..2baf3320 100755 --- a/bin/definitionLint +++ b/bin/definitionLint @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -253,10 +259,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -269,6 +271,14 @@ Env::requireLoad() { done } +# @description create a temp file using default TMPDIR variable +# initialized in _includes/_commonHeader.sh +# @env TMPDIR String (default value /tmp) +# @arg $1 templateName:String template name to use(optional) +Framework::createTempFile() { + mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" +} + # @description Log namespace provides 2 kind of functions # - Log::display* allows to display given message with # given display level @@ -914,21 +924,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -937,10 +947,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -961,7 +971,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -983,7 +993,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -993,18 +1003,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1071,15 +1081,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1318,15 +1337,15 @@ definitionLintCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 13/15 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1358,15 +1377,15 @@ definitionLintCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 15/15 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1439,7 +1458,7 @@ definitionLintCommand() { # shellcheck disable=SC2054 helpArray=(define\ output\ format\ of\ this\ command) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: plain' + echo " Default value: plain" echo ' Possible values: plain|checkstyle' echo echo -e "${__HELP_TITLE_COLOR}GLOBAL OPTIONS:${__RESET_COLOR}" @@ -1483,7 +1502,7 @@ definitionLintCommand() { # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1505,7 +1524,7 @@ definitionLintCommand() { # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1516,7 +1535,7 @@ definitionLintCommand() { # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e """ for each definition file: - check that all mandatory methods are existing diff --git a/bin/doc b/bin/doc index 7bfcd1ad..921737af 100755 --- a/bin/doc +++ b/bin/doc @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -356,10 +362,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -372,6 +374,14 @@ Env::requireLoad() { done } +# @description create a temp file using default TMPDIR variable +# initialized in _includes/_commonHeader.sh +# @env TMPDIR String (default value /tmp) +# @arg $1 templateName:String template name to use(optional) +Framework::createTempFile() { + mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" +} + # @description Log namespace provides 2 kind of functions # - Log::display* allows to display given message with # given display level @@ -1137,14 +1147,6 @@ File::elapsedTimeSinceLastModification() { echo -n "${diff}" } -# @description create a temp file using default TMPDIR variable -# initialized in _includes/_commonHeader.sh -# @env TMPDIR String (default value /tmp) -# @arg $1 templateName:String template name to use(optional) -Framework::createTempFile() { - mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" -} - # @description pull git directory only if no change has been detected # @arg $1 dir:String the git directory to pull # @exitcode 0 on successful pulling @@ -1305,21 +1307,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -1328,10 +1330,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -1352,7 +1354,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -1374,7 +1376,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1384,18 +1386,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1462,15 +1464,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1829,15 +1840,15 @@ docCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 18/20 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1869,15 +1880,15 @@ docCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 20/20 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1923,21 +1934,21 @@ docCommand() { # shellcheck disable=SC2054 helpArray=(vendor\ image\ to\ use:\ alpine\|ubuntu) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: ubuntu' + echo " Default value: ubuntu" echo ' Possible values: alpine|ubuntu' echo -e " ${__HELP_OPTION_COLOR}--bash-version ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 helpArray=(version\ of\ bash\ to\ use:\ 4.4\|5.0\|5.1\|5.2) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: 5.1' + echo " Default value: 5.1" echo ' Possible values: 4.4|5.0|5.1|5.2' echo -e " ${__HELP_OPTION_COLOR}--bash-base-image ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 helpArray=(bash\ bash\ image\ to\ use\ \(eg:\ ubuntu:20.04\,\ amd64/bash:4.4-alpine3.18\)) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: ubuntu:20.04' + echo " Default value: ubuntu:20.04" echo -e " ${__HELP_OPTION_COLOR}--branch-name ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1995,7 +2006,7 @@ docCommand() { # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -2017,7 +2028,7 @@ docCommand() { # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -2028,7 +2039,7 @@ docCommand() { # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e """ INTERNAL TOOL""" echo diff --git a/bin/dockerLint b/bin/dockerLint index 94db44e7..d246e40a 100755 --- a/bin/dockerLint +++ b/bin/dockerLint @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -253,10 +259,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -1027,21 +1029,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -1050,10 +1052,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -1074,7 +1076,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -1096,7 +1098,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1106,18 +1108,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1184,15 +1186,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1428,15 +1439,15 @@ dockerLintCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 12/14 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1468,15 +1479,15 @@ dockerLintCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 14/14 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1552,7 +1563,7 @@ dockerLintCommand() { # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1574,7 +1585,7 @@ dockerLintCommand() { # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1585,7 +1596,7 @@ dockerLintCommand() { # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e """ - installs new hadolint version(>${MIN_HADOLINT_VERSION}) automatically - lint this project files using default files filter diff --git a/bin/findShebangFiles b/bin/findShebangFiles index d4e860c0..69be3072 100755 --- a/bin/findShebangFiles +++ b/bin/findShebangFiles @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -267,10 +273,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -311,6 +313,14 @@ File::detectBashFile() { fi } +# @description create a temp file using default TMPDIR variable +# initialized in _includes/_commonHeader.sh +# @env TMPDIR String (default value /tmp) +# @arg $1 templateName:String template name to use(optional) +Framework::createTempFile() { + mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" +} + # @description Log namespace provides 2 kind of functions # - Log::display* allows to display given message with # given display level @@ -758,21 +768,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -781,10 +791,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -805,7 +815,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -827,7 +837,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -837,18 +847,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -915,15 +925,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1128,15 +1147,15 @@ findShebangFiles() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 12/14 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1168,15 +1187,15 @@ findShebangFiles() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 14/14 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1252,7 +1271,7 @@ findShebangFiles() { # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1274,7 +1293,7 @@ findShebangFiles() { # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1285,7 +1304,7 @@ findShebangFiles() { # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e """ display list of all files having a bash shebang in the current repository diff --git a/bin/frameworkLint b/bin/frameworkLint index 903c96cf..1dfe8a91 100755 --- a/bin/frameworkLint +++ b/bin/frameworkLint @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -310,10 +316,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -382,6 +384,14 @@ Filters::commentLines() { grep -vxE "[[:blank:]]*(${commentLinePrefix:-#}.*)?" "$@" || test $? = 1 } +# @description create a temp file using default TMPDIR variable +# initialized in _includes/_commonHeader.sh +# @env TMPDIR String (default value /tmp) +# @arg $1 templateName:String template name to use(optional) +Framework::createTempFile() { + mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" +} + # @description Log namespace provides 2 kind of functions # - Log::display* allows to display given message with # given display level @@ -846,21 +856,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -869,10 +879,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -893,7 +903,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -915,7 +925,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -925,18 +935,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1003,15 +1013,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1267,15 +1286,15 @@ frameworkLintCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 14/16 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1307,15 +1326,15 @@ frameworkLintCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 16/16 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1361,7 +1380,7 @@ frameworkLintCommand() { # shellcheck disable=SC2054 helpArray=(define\ output\ format\ of\ this\ command) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: plain' + echo " Default value: plain" echo ' Possible values: plain|checkstyle' echo -e " ${__HELP_OPTION_COLOR}--expected-warnings-count ${__HELP_NORMAL} {single}" local -a helpArray @@ -1410,7 +1429,7 @@ frameworkLintCommand() { # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1432,7 +1451,7 @@ frameworkLintCommand() { # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1443,7 +1462,7 @@ frameworkLintCommand() { # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e """ Lint files of the current repository - check if all Namespace::functions are existing in the framework diff --git a/bin/installFacadeExample b/bin/installFacadeExample index 2328f89d..7d1a3361 100755 --- a/bin/installFacadeExample +++ b/bin/installFacadeExample @@ -27,10 +27,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -244,10 +250,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") diff --git a/bin/megalinter b/bin/megalinter index 0149f728..d809c0c7 100755 --- a/bin/megalinter +++ b/bin/megalinter @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -269,10 +275,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -285,6 +287,14 @@ Env::requireLoad() { done } +# @description create a temp file using default TMPDIR variable +# initialized in _includes/_commonHeader.sh +# @env TMPDIR String (default value /tmp) +# @arg $1 templateName:String template name to use(optional) +Framework::createTempFile() { + mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" +} + # @description Retrieve the latest version number of a github release using Github API using retry # repo arg with fchastanet/bash-tools value would match https://github.com/fchastanet/bash-tools # @arg $1 repo:String repository in the format fchastanet/bash-tools @@ -888,21 +898,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -911,10 +921,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -935,7 +945,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -957,7 +967,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -967,18 +977,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1045,15 +1055,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1386,15 +1405,15 @@ megalinterCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 19/21 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1426,15 +1445,15 @@ megalinterCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 21/21 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1479,7 +1498,7 @@ megalinterCommand() { # shellcheck disable=SC2054 helpArray=(define\ output\ format\ of\ this\ command) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: plain' + echo " Default value: plain" echo ' Possible values: plain|json' echo -e " ${__HELP_OPTION_COLOR}--fix${__HELP_NORMAL} {single}" local -a helpArray @@ -1501,7 +1520,7 @@ megalinterCommand() { # shellcheck disable=SC2054 helpArray=(Specify\ docker\ megalinter\ image\ name\ to\ use) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: oxsecurity/megalinter-terraform:v7.4.0' + echo " Default value: oxsecurity/megalinter-terraform:v7.4.0" echo -e " ${__HELP_OPTION_COLOR}--check-megalinter-version${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1512,7 +1531,7 @@ megalinterCommand() { # shellcheck disable=SC2054 helpArray=(Specify\ megalinter\ config\ filename\ to\ use) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: .mega-linter.yml' + echo " Default value: .mega-linter.yml" echo echo -e "${__HELP_TITLE_COLOR}GLOBAL OPTIONS:${__RESET_COLOR}" echo -e " ${__HELP_OPTION_COLOR}--bash-framework-config ${__HELP_NORMAL} {single}" @@ -1555,7 +1574,7 @@ megalinterCommand() { # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1577,7 +1596,7 @@ megalinterCommand() { # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1588,7 +1607,7 @@ megalinterCommand() { # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e """ megalinter image oxsecurity/megalinter-terraform:v7.4.0 will be used. diff --git a/bin/plantuml b/bin/plantuml index f53b3b2f..d5d2e2a1 100755 --- a/bin/plantuml +++ b/bin/plantuml @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -253,10 +259,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -739,21 +741,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -762,10 +764,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -786,7 +788,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -808,7 +810,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -818,18 +820,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -896,15 +898,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1159,15 +1170,15 @@ plantumlCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 15/17 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1199,15 +1210,15 @@ plantumlCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 17/17 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1324,7 +1335,7 @@ plantumlCommand() { # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1346,7 +1357,7 @@ plantumlCommand() { # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1357,7 +1368,7 @@ plantumlCommand() { # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e """ Generates plantuml diagrams from puml files in formats provided diff --git a/bin/runBuildContainer b/bin/runBuildContainer index e2d2f652..cf49e85e 100755 --- a/bin/runBuildContainer +++ b/bin/runBuildContainer @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -356,10 +362,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -372,6 +374,14 @@ Env::requireLoad() { done } +# @description create a temp file using default TMPDIR variable +# initialized in _includes/_commonHeader.sh +# @env TMPDIR String (default value /tmp) +# @arg $1 templateName:String template name to use(optional) +Framework::createTempFile() { + mktemp -p "${TMPDIR:-/tmp}" -t "${1:-}.XXXXXXXXXXXX" +} + # @description Log namespace provides 2 kind of functions # - Log::display* allows to display given message with # given display level @@ -876,21 +886,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -899,10 +909,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -923,7 +933,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -945,7 +955,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -955,18 +965,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1033,15 +1043,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1402,15 +1421,15 @@ runBuildContainerCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 18/20 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1442,15 +1461,15 @@ runBuildContainerCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 20/20 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1512,21 +1531,21 @@ runBuildContainerCommand() { # shellcheck disable=SC2054 helpArray=(vendor\ image\ to\ use:\ alpine\|ubuntu) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: ubuntu' + echo " Default value: ubuntu" echo ' Possible values: alpine|ubuntu' echo -e " ${__HELP_OPTION_COLOR}--bash-version ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 helpArray=(version\ of\ bash\ to\ use:\ 4.4\|5.0\|5.1\|5.2) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: 5.1' + echo " Default value: 5.1" echo ' Possible values: 4.4|5.0|5.1|5.2' echo -e " ${__HELP_OPTION_COLOR}--bash-base-image ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 helpArray=(bash\ bash\ image\ to\ use\ \(eg:\ ubuntu:20.04\,\ amd64/bash:4.4-alpine3.18\)) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: ubuntu:20.04' + echo " Default value: ubuntu:20.04" echo -e " ${__HELP_OPTION_COLOR}--branch-name ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1584,7 +1603,7 @@ runBuildContainerCommand() { # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1606,7 +1625,7 @@ runBuildContainerCommand() { # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1617,7 +1636,7 @@ runBuildContainerCommand() { # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e """ run the container specified by args provided. Command to run is passed via the rest of arguments. diff --git a/bin/shellcheckLint b/bin/shellcheckLint index 5c7c7ec9..fea7853c 100755 --- a/bin/shellcheckLint +++ b/bin/shellcheckLint @@ -25,10 +25,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -267,10 +273,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -1090,21 +1092,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -1113,10 +1115,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -1137,7 +1139,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -1159,7 +1161,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1169,18 +1171,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1247,15 +1249,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1513,15 +1524,15 @@ shellcheckLintCommand() { updateArgListQuietCallback "${options_parse_arg}" ;; # Option 15/17 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1553,15 +1564,15 @@ shellcheckLintCommand() { updateArgListLogFileCallback "${options_parse_arg}" "${optionLogFile}" ;; # Option 17/17 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1625,7 +1636,7 @@ shellcheckLintCommand() { # shellcheck disable=SC2054 helpArray=(define\ output\ format\ of\ this\ command) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: tty' + echo " Default value: tty" echo ' Possible values: checkstyle|diff|gcc|json|json1|quiet|tty' echo -e " ${__HELP_OPTION_COLOR}--staged${__HELP_NORMAL} {single}" local -a helpArray @@ -1679,7 +1690,7 @@ shellcheckLintCommand() { # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1701,7 +1712,7 @@ shellcheckLintCommand() { # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1712,7 +1723,7 @@ shellcheckLintCommand() { # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e """ shellcheck wrapper that will - install new shellcheck version(${MIN_SHELLCHECK_VERSION}) automatically diff --git a/bin/test b/bin/test index cdca7d48..9443880b 100755 --- a/bin/test +++ b/bin/test @@ -24,10 +24,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters @@ -408,10 +414,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") @@ -1013,21 +1015,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -1036,10 +1038,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -1060,7 +1062,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -1082,7 +1084,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1092,18 +1094,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -1170,15 +1172,24 @@ BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION="${BASH_FRAMEWORK_LOG_FILE_MAX_ROTATION:-5} EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi @@ -1573,15 +1584,15 @@ testCommand() { everyOptOrArgCallback "optionQuiet" "${options_parse_arg}" "${optionQuiet}" || true ;; # Option 18/20 - # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionLogLevel --log-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --log-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionLogLevel >= 1)); then @@ -1617,15 +1628,15 @@ testCommand() { everyOptOrArgCallback "optionLogFile" "${options_parse_arg}" "${optionLogFile}" || true ;; # Option 20/20 - # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERROR|WARNING|INFO|DEBUG|TRACE' regexp '' + # Option optionDisplayLevel --display-level variableType String min 0 max 1 authorizedValues 'OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' regexp '' --display-level) shift if (($# == 0)); then Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - a value needs to be specified" return 1 fi - if [[ ! "$1" =~ OFF|ERROR|WARNING|INFO|DEBUG|TRACE ]]; then - Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERROR|WARNING|INFO|DEBUG|TRACE)" + if [[ ! "$1" =~ OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE ]]; then + Log::displayError "Command ${SCRIPT_NAME} - Option ${options_parse_arg} - value '$1' is not part of authorized values(OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE)" return 1 fi if ((options_parse_optionParsedCountOptionDisplayLevel >= 1)); then @@ -1697,21 +1708,21 @@ testCommand() { # shellcheck disable=SC2054 helpArray=(vendor\ image\ to\ use:\ alpine\|ubuntu) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: ubuntu' + echo " Default value: ubuntu" echo ' Possible values: alpine|ubuntu' echo -e " ${__HELP_OPTION_COLOR}--bash-version ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 helpArray=(version\ of\ bash\ to\ use:\ 4.4\|5.0\|5.1\|5.2) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: 5.1' + echo " Default value: 5.1" echo ' Possible values: 4.4|5.0|5.1|5.2' echo -e " ${__HELP_OPTION_COLOR}--bash-base-image ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 helpArray=(bash\ bash\ image\ to\ use\ \(eg:\ ubuntu:20.04\,\ amd64/bash:4.4-alpine3.18\)) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: ubuntu:20.04' + echo " Default value: ubuntu:20.04" echo -e " ${__HELP_OPTION_COLOR}--branch-name ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1769,7 +1780,7 @@ testCommand() { # shellcheck disable=SC2054 helpArray=(choose\ color\ theme\ -\ default-force\ means\ colors\ will\ be\ produced\ even\ if\ command\ is\ piped) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Default value: default' + echo " Default value: default" echo ' Possible values: default|default-force|noColor' echo -e " ${__HELP_OPTION_COLOR}--help${__HELP_NORMAL}, ${__HELP_OPTION_COLOR}-h${__HELP_NORMAL} {single}" local -a helpArray @@ -1791,7 +1802,7 @@ testCommand() { # shellcheck disable=SC2054 helpArray=(Set\ log\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e " ${__HELP_OPTION_COLOR}--log-file ${__HELP_NORMAL} {single}" local -a helpArray # shellcheck disable=SC2054 @@ -1802,7 +1813,7 @@ testCommand() { # shellcheck disable=SC2054 helpArray=(set\ display\ level) echo -e " $(Array::wrap2 " " 76 4 "${helpArray[@]}")" - echo ' Possible values: OFF|ERROR|WARNING|INFO|DEBUG|TRACE' + echo ' Possible values: OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE' echo -e """ Launch bats inside docker container diff --git a/src/Env/requireLoad.sh b/src/Env/requireLoad.sh index 0ca5b809..6424d028 100755 --- a/src/Env/requireLoad.sh +++ b/src/Env/requireLoad.sh @@ -19,10 +19,6 @@ Env::requireLoad() { if [[ -f "${FRAMEWORK_ROOT_DIR}/.framework-config" ]]; then configFiles+=("${FRAMEWORK_ROOT_DIR}/.framework-config") fi - if [[ -n "${optionBashFrameworkConfig}" && -f "${optionBashFrameworkConfig}" ]]; then - # shellcheck disable=SC2034 - configFiles+=("${optionBashFrameworkConfig}") - fi configFiles+=("${optionEnvFiles[@]}") configFiles+=("${defaultFiles[@]}") diff --git a/src/_binaries/options/options.base.tpl b/src/_binaries/options/options.base.tpl index f217c25a..703f5075 100644 --- a/src/_binaries/options/options.base.tpl +++ b/src/_binaries/options/options.base.tpl @@ -80,7 +80,7 @@ --help "Set log level" \ --group zzzGroupGlobalOptionsFunction \ --alt "--log-level" \ - --authorized-values "OFF|ERROR|WARNING|INFO|DEBUG|TRACE" \ + --authorized-values "OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE" \ --callback "optionLogLevelCallback" \ --callback updateArgListLogLevelCallback \ --variable-name "optionLogLevel" \ @@ -101,7 +101,7 @@ --help "set display level" \ --group zzzGroupGlobalOptionsFunction \ --alt "--display-level" \ - --authorized-values "OFF|ERROR|WARNING|INFO|DEBUG|TRACE" \ + --authorized-values "OFF|ERR|ERROR|WARN|WARNING|INFO|DEBUG|TRACE" \ --callback optionDisplayLevelCallback \ --callback updateArgListDisplayLevelCallback \ --variable-name "optionDisplayLevel" \ @@ -238,21 +238,21 @@ optionEnvFileCallback() { optionInfoVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='--verbose' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_INFO} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_INFO}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionDebugVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_DEBUG} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionTraceVerboseCallback() { BASH_FRAMEWORK_ARGS_VERBOSE_OPTION='-vvv' BASH_FRAMEWORK_ARGS_VERBOSE=${__VERBOSE_LEVEL_TRACE} - BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${__LEVEL_DEBUG}" >> "${overrideEnvFile}" } getLevel() { @@ -261,10 +261,10 @@ getLevel() { OFF) echo "${__LEVEL_OFF}" ;; - ERROR) + ERR | ERROR) echo "${__LEVEL_ERROR}" ;; - WARNING) + WARN | WARNING) echo "${__LEVEL_WARNING}" ;; INFO) @@ -285,7 +285,7 @@ getVerboseLevel() { OFF) echo "${__VERBOSE_LEVEL_OFF}" ;; - ERROR | WARNING | INFO) + ERR | ERROR | WARN | WARNING | INFO) echo "${__VERBOSE_LEVEL_INFO}" ;; DEBUG) @@ -307,7 +307,7 @@ optionDisplayLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_DISPLAY_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -317,18 +317,18 @@ optionLogLevelCallback() { logLevel="$(getLevel "${level}")" verboseLevel="$(getVerboseLevel "${level}")" BASH_FRAMEWORK_ARGS_VERBOSE=${verboseLevel} - BASH_FRAMEWORK_LOG_LEVEL=${logLevel} + echo "BASH_FRAMEWORK_LOG_LEVEL=${logLevel}" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionLogFileCallback() { local logFile="$2" - BASH_FRAMEWORK_LOG_FILE="${logFile}" + echo "BASH_FRAMEWORK_LOG_FILE='${logFile}'" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden optionQuietCallback() { - BASH_FRAMEWORK_QUIET_MODE=1 + echo "BASH_FRAMEWORK_QUIET_MODE=1" >> "${overrideEnvFile}" } # shellcheck disable=SC2317 # if function is overridden @@ -363,15 +363,24 @@ defaultFrameworkConfig="$( EOF )" +overrideEnvFile="$(Framework::createTempFile "overrideEnvFile")" + commandOptionParseFinished() { # load default template framework config - # shellcheck disable=SC2034 defaultEnvFile="${PERSISTENT_TMPDIR}/.framework-config" echo "${defaultFrameworkConfig}" > "${defaultEnvFile}" - - Env::requireLoad "${defaultEnvFile}" + local -a files=("${defaultEnvFile}") + if [[ -f "${envFile}" ]]; then + files+=("${envFile}") + fi + # shellcheck disable=SC2154 + if [[ -f "${optionBashFrameworkConfig}" ]]; then + files+=("${optionBashFrameworkConfig}") + fi + files+=("${overrideEnvFile}") + Env::requireLoad "${files[@]}" Log::requireLoad - + # shellcheck disable=SC2154 if [[ "${optionConfig}" = "1" ]]; then displayConfig fi diff --git a/src/_includes/_mandatoryHeader.sh b/src/_includes/_mandatoryHeader.sh index 89f86e55..f858f16a 100755 --- a/src/_includes/_mandatoryHeader.sh +++ b/src/_includes/_mandatoryHeader.sh @@ -16,10 +16,16 @@ set -o errexit # Command Substitution can inherit errexit option since bash v4.4 shopt -s inherit_errexit || true +# if set, and job control is not active, the shell runs the last command +# of a pipeline not executed in the background in the current shell +# environment. +shopt -s lastpipe + # a log is generated when a command fails set -o errtrace -# use nullglob so that (file*.php) will return an empty array if no file matches the wildcard +# use nullglob so that (file*.php) will return an empty array if no file +# matches the wildcard shopt -s nullglob # ensure regexp are interpreted without accentuated characters