added assert_* helpers

This commit is contained in:
Gerhard Hoffmann 2022-06-05 21:41:22 +02:00
parent a0602c820c
commit e419b74e46

View File

@ -80,4 +80,35 @@ if [ "${general_utils_sourced:-1}" = "1" ]; then # include only once
echo "INFO: $2 completed successfully" >&2
fi
}
assert_s () {
if [ -z ${!1} ]; then
log_fatal "$1 not set"
fi
log_debug "$1=${!1}"
}
assert_d () {
if [ ! -d ${!1} ]; then
log_fatal "$1 does not exist"
fi
log_debug "$1=${!1}"
}
assert_f () {
if [ ! -f ${!1} ]; then
log_fatal "$1 does not exist"
fi
log_debug "$1=${!1}"
}
assert_a () {
local readonly __m="${1}[@]"
local readonly __n=(${!__m})
local __len=${#__n[@]}
if [ $__len -eq 0 ]; then
log_fatal "$1 not set"
fi
log_debug "$1=$__n"
}
fi