mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2024-12-18 22:27:51 +00:00
fix shellcheck errors
shellcheck 0.4.7 seems to have come up with new checks and now complains about yet more possible issues. fixed them all as good as i could.
This commit is contained in:
parent
cf7d25e3d1
commit
236e3c7eca
@ -27,6 +27,7 @@
|
||||
# - We do not bash-expand defaults, so setting '~/app' as a default will not resolve to ${HOME}.
|
||||
# you can use bash variables to work around this (so use ${HOME} instead)
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
|
||||
-f --file [arg] Filename to process. Required.
|
||||
-t --temp [arg] Location of tempfile. Default="/tmp/bar"
|
||||
@ -37,6 +38,7 @@ read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
|
||||
-1 --one Do just one thing
|
||||
EOF
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
read -r -d '' __helptext <<-'EOF' || true # exits non-zero when EOF encountered
|
||||
This is Bash3 Boilerplate's help text. Feel free to add any description of your
|
||||
program or elaborate more on command-line arguments. This section is not
|
||||
@ -59,6 +61,7 @@ trap __b3bp_cleanup_before_exit EXIT
|
||||
__b3bp_err_report() {
|
||||
local error_code
|
||||
error_code=${?}
|
||||
# shellcheck disable=SC2154
|
||||
error "Error in ${__file} in function ${1} on line ${2}"
|
||||
exit ${error_code}
|
||||
}
|
||||
@ -104,9 +107,13 @@ fi
|
||||
### Runtime
|
||||
##############################################################################
|
||||
|
||||
# shellcheck disable=SC2154
|
||||
info "__i_am_main_script: ${__i_am_main_script}"
|
||||
# shellcheck disable=SC2154
|
||||
info "__file: ${__file}"
|
||||
# shellcheck disable=SC2154
|
||||
info "__dir: ${__dir}"
|
||||
# shellcheck disable=SC2154
|
||||
info "__base: ${__base}"
|
||||
info "OSTYPE: ${OSTYPE}"
|
||||
|
||||
@ -115,7 +122,7 @@ info "arg_d: ${arg_d}"
|
||||
info "arg_v: ${arg_v}"
|
||||
info "arg_h: ${arg_h}"
|
||||
|
||||
info "$(echo -e "multiple lines example - line #1\nmultiple lines example - line #2\nimagine logging the output of 'ls -al /path/'")"
|
||||
info "$(echo -e "multiple lines example - line #1\\nmultiple lines example - line #2\\nimagine logging the output of 'ls -al /path/'")"
|
||||
|
||||
# All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software
|
||||
debug "Info useful to developers for debugging the application, not useful during operations."
|
||||
|
24
main.sh
24
main.sh
@ -62,26 +62,26 @@ function __b3bp_log () {
|
||||
shift
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
local color_debug="\x1b[35m"
|
||||
local color_debug="\\x1b[35m"
|
||||
# shellcheck disable=SC2034
|
||||
local color_info="\x1b[32m"
|
||||
local color_info="\\x1b[32m"
|
||||
# shellcheck disable=SC2034
|
||||
local color_notice="\x1b[34m"
|
||||
local color_notice="\\x1b[34m"
|
||||
# shellcheck disable=SC2034
|
||||
local color_warning="\x1b[33m"
|
||||
local color_warning="\\x1b[33m"
|
||||
# shellcheck disable=SC2034
|
||||
local color_error="\x1b[31m"
|
||||
local color_error="\\x1b[31m"
|
||||
# shellcheck disable=SC2034
|
||||
local color_critical="\x1b[1;31m"
|
||||
local color_critical="\\x1b[1;31m"
|
||||
# shellcheck disable=SC2034
|
||||
local color_alert="\x1b[1;33;41m"
|
||||
local color_alert="\\x1b[1;33;41m"
|
||||
# shellcheck disable=SC2034
|
||||
local color_emergency="\x1b[1;4;5;33;41m"
|
||||
local color_emergency="\\x1b[1;4;5;33;41m"
|
||||
|
||||
local colorvar="color_${log_level}"
|
||||
|
||||
local color="${!colorvar:-${color_error}}"
|
||||
local color_reset="\x1b[0m"
|
||||
local color_reset="\\x1b[0m"
|
||||
|
||||
if [[ "${NO_COLOR:-}" = "true" ]] || ( [[ "${TERM:-}" != "xterm"* ]] && [[ "${TERM:-}" != "screen"* ]] ) || [[ ! -t 2 ]]; then
|
||||
if [[ "${NO_COLOR:-}" != "false" ]]; then
|
||||
@ -190,7 +190,7 @@ while read -r __b3bp_tmp_line; do
|
||||
|
||||
[[ "${__b3bp_tmp_opt:-}" ]] || continue
|
||||
|
||||
if [[ "${__b3bp_tmp_line}" =~ (^|\.\ *)Default= ]]; then
|
||||
if [[ "${__b3bp_tmp_line}" =~ ^Default= ]] || [[ "${__b3bp_tmp_line}" =~ \.\ *Default= ]]; then
|
||||
# ignore default value if option does not have an argument
|
||||
__b3bp_tmp_varname="__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}"
|
||||
|
||||
@ -208,7 +208,7 @@ while read -r __b3bp_tmp_line; do
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${__b3bp_tmp_line}" =~ (^|\.\ *)Required\. ]]; then
|
||||
if [[ "${__b3bp_tmp_line}" =~ ^Required\. ]] || [[ "${__b3bp_tmp_line}" =~ \.\ *Required\. ]]; then
|
||||
# remember that this option requires an argument
|
||||
printf -v "__b3bp_tmp_has_arg_${__b3bp_tmp_opt:0:1}" '%s' "2"
|
||||
fi
|
||||
@ -380,7 +380,7 @@ info "arg_d: ${arg_d}"
|
||||
info "arg_v: ${arg_v}"
|
||||
info "arg_h: ${arg_h}"
|
||||
|
||||
info "$(echo -e "multiple lines example - line #1\nmultiple lines example - line #2\nimagine logging the output of 'ls -al /path/'")"
|
||||
info "$(echo -e "multiple lines example - line #1\\nmultiple lines example - line #2\\nimagine logging the output of 'ls -al /path/'")"
|
||||
|
||||
# All of these go to STDERR, so you can use STDOUT for piping machine readable information to other software
|
||||
debug "Info useful to developers for debugging the application, not useful during operations."
|
||||
|
@ -57,7 +57,7 @@ function ini_val() {
|
||||
echo "${key}${delim}${val}" >> "${file}"
|
||||
else
|
||||
# add to section
|
||||
sed -i.bak -e "/\[${section}\]/a ${key}${delim}${val}" "${file}"
|
||||
sed -i.bak -e "/\\[${section}\\]/a ${key}${delim}${val}" "${file}"
|
||||
# this .bak dance is done for BSD/GNU portability: http://stackoverflow.com/a/22084103/151666
|
||||
rm -f "${file}.bak"
|
||||
fi
|
||||
|
@ -41,8 +41,8 @@ __accptstTmpDir=$(mktemp -d "${__sysTmpDir}/${__base}.XXXXXX")
|
||||
function cleanup_before_exit () { rm -r "${__accptstTmpDir:?}"; }
|
||||
trap cleanup_before_exit EXIT
|
||||
|
||||
cmdSed=sed
|
||||
cmdTimeout=timeout
|
||||
cmdSed="sed"
|
||||
cmdTimeout="timeout"
|
||||
|
||||
if [[ "${OSTYPE}" = "darwin"* ]]; then
|
||||
cmdSed=gsed
|
||||
@ -98,7 +98,7 @@ while IFS=$'\n' read -r scenario; do
|
||||
-e "s@${USER:-travis}@{user}@g" "${curFile}" \
|
||||
-e "s@travis@{user}@g" "${curFile}" \
|
||||
-e "s@kvz@{user}@g" "${curFile}" \
|
||||
-e "s@{root}/node_modules/\.bin/node@{node}@g" "${curFile}" \
|
||||
-e "s@{root}/node_modules/\\.bin/node@{node}@g" "${curFile}" \
|
||||
-e "s@{home}/build/{user}/fre{node}@{node}@g" "${curFile}" \
|
||||
-e "s@${HOSTNAME}@{hostname}@g" "${curFile}" \
|
||||
-e "s@${__arch}@{arch}@g" "${curFile}" \
|
||||
@ -177,10 +177,10 @@ while IFS=$'\n' read -r scenario; do
|
||||
fi
|
||||
|
||||
if ! diff --strip-trailing-cr "${__dir}/fixture/${scenario}.${typ}" "${curFile}"; then
|
||||
echo -e "\n\n==> MISMATCH OF: ${scenario}.${typ} ---^"
|
||||
echo -e "\n\n==> EXPECTED STDIO: "
|
||||
echo -e "\\n\\n==> MISMATCH OF: ${scenario}.${typ} ---^"
|
||||
echo -e "\\n\\n==> EXPECTED STDIO: "
|
||||
cat "${__dir}/fixture/${scenario}.stdio" || true
|
||||
echo -e "\n\n==> ACTUAL STDIO: "
|
||||
echo -e "\\n\\n==> ACTUAL STDIO: "
|
||||
cat "${__accptstTmpDir}/${scenario}.stdio" || true
|
||||
exit 1
|
||||
fi
|
||||
@ -195,8 +195,7 @@ done <<< "$(find "${__dir}/scenario" -type f -iname 'run.sh')"
|
||||
|
||||
# Ensure correct syntax with all available bashes
|
||||
|
||||
if bashes=($(which -a bash 2> /dev/null )); then
|
||||
for bash in "${bashes[@]}"; do
|
||||
while IFS=$'\n' read -r bash; do
|
||||
# shellcheck disable=SC2016
|
||||
echo "==> ${bash} -n $(${bash} -c 'echo "(${BASH_VERSION})"')"
|
||||
pushd "${__root}" > /dev/null
|
||||
@ -224,8 +223,7 @@ if bashes=($(which -a bash 2> /dev/null )); then
|
||||
cat "${__accptstTmpDir}/${bash//\//.}.err"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done <<< "$(which -a bash 2>/dev/null)"
|
||||
|
||||
# do some shellcheck linting
|
||||
if [[ "$(command -v shellcheck)" ]]; then
|
||||
|
@ -6,8 +6,6 @@ set -o nounset
|
||||
|
||||
# Set magic variables for current FILE & DIR
|
||||
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
|
||||
__base="$(basename "${__file}" .sh)"
|
||||
__root="$(cd "$(dirname "$(dirname "$(dirname "${__dir}")")")" && pwd)"
|
||||
|
||||
# echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||
|
@ -22,6 +22,8 @@ read -r -d '' __usage <<-'EOF' || true # exits non-zero when EOF encountered
|
||||
More description.
|
||||
EOF
|
||||
|
||||
export __usage
|
||||
|
||||
echo "ACCPTST:STDIO_REPLACE_DATETIMES"
|
||||
|
||||
# shellcheck source=main.sh
|
||||
|
@ -42,7 +42,7 @@ for doc in "README" "FAQ" "CHANGELOG"; do
|
||||
permalink="/${targetName}/"
|
||||
subtitle="$(tr '[:lower:]' '[:upper:]' <<< "${targetName:0:1}")${targetName:1} | "
|
||||
redirectFrom="/${doc}.md/"
|
||||
backLink="\n\n<a href=\"/\">« Home</a>"
|
||||
backLink='\n\n<a href="/">« Home</a>'
|
||||
if [[ "${doc}" = "README" ]]; then
|
||||
targetName="index"
|
||||
permalink="/"
|
||||
|
Loading…
Reference in New Issue
Block a user