sequencer - add more options to info,warning,... output

This commit is contained in:
2022-06-11 09:43:53 +02:00
parent 63169f3153
commit ad93a5eb9c

View File

@@ -319,7 +319,9 @@ USAGE_API
Output [STRING] (can be multiline) to stdout according to log level.
[OPTIONS]
-a : Append [STRING] skipping leading " [ ] " prefix
-d : No leading " [ ] " prefix
-e : Output to stderr
-n : No newline
USAGE_API
echo -e "${col_green} echoinfo [...]${col_off}"
@@ -382,14 +384,18 @@ USAGE_API
# Construct log messages
#
# [OPTIONS]
# -a : append text (no info and timestamp)
# -a : append text (placeholder for info and timestamp)
# Uses color from last sqr::log call without -a
# -d : no info and timestamp
# -e : Output to stderr
# -n : no newline
# -- : End of options
#
sqr::log () {
sqr::debugPause
local appendText=
local direct=0 # no prefix and timestamp
local newline='\n'
local col_end="${col_off}"
local outp='/dev/stdout'
@@ -397,18 +403,28 @@ USAGE_API
shift
local log_color="${1:-}"
shift
for _ in "${@}" ; do
case "${1:-}" in
--)
shift && break ;;
-a)
appendText=1
shift ;;
-e)
outp='/dev/stderr'
shift ;;
# Only output newline on empty args
if ! (( $# )) ; then
direct=1
newline='\n'
fi
while getopts "aden" arg; do
case "${arg}" in
a)
appendText=1 ;;
d)
direct=1 ;;
e)
outp='/dev/stderr' ;;
n)
newline='' ;;
*)
;;
esac
done
shift "$((OPTIND-1))"; OPTIND=1
[[ -z "${log_color}" ]] && col_end=""
@@ -417,23 +433,28 @@ USAGE_API
while IFS=$'\n' read -r log_line ; do
printf '%b' "${log_color}" >${outp}
if [[ -n "${LOG_TIME}" ]] ; then
if (( appendText )) ; then
printf '%24s' "" >${outp}
else
printf '%s ' "$(date -u +"%Y-%m-%d %H:%M:%S UTC")" >${outp}
if ! (( direct )) ; then
if [[ -n "${LOG_TIME}" ]] ; then
if (( appendText )) ; then
printf '%24s' "" >${outp}
else
printf '%s ' "$(date -u +"%Y-%m-%d %H:%M:%S UTC")" >${outp}
fi
fi
fi
if (( ! appendText )) ; then
printf " %3s " "[${log_level}]" >${outp}
printf "%s" "${log_line}" >${outp}
if (( ! appendText )) ; then
printf " %3s " "[${log_level}]" >${outp}
printf "%s" "${log_line}" >${outp}
else
# +3 : "[] "
printf "%$((${#log_level} + 4))s%s" "" "${log_line}" >${outp}
fi
else
# +3 : "[] "
printf "%$((${#log_level} + 4))s%s" "" "${log_line}" >${outp}
# direct output
printf '%s' "${log_line}"
fi
printf '%b\n' "${col_end}" >${outp}
printf '%b'"${newline}" "${col_end}" >${outp}
done <<< "${@:-}"
sqr::debugContinue
}
@@ -504,7 +525,7 @@ USAGE_API
esac
}
# Echo additional line to info correctly indented
# Echo correctly indented additional line to info
readonly _sqr_indentHelp=' : '
readonly _sqr_indentExe=' '
readonly _sqr_indentAppendHelp=' '
@@ -822,7 +843,7 @@ addConf() {
for _ in "$@" ; do
case "${1:-}" in
-c) # create a new file
-c) # create a new file
confMode="-c"
shift ;;
-a) # append to existing file
@@ -838,7 +859,7 @@ addConf() {
transferCmd="cat"
shift ;;
*) # default
if [ "$confMode" == "" ] ; then
if [ "$confMode" == "" ] ; then
error "Parameter 1 (-a|-c|-m|-s) missing for addConf()"
exit 0
fi ;;
@@ -863,7 +884,7 @@ addConf() {
sqr::echo -n " [i] Writing ${dest} ..."
if [[ ${confMode} != "-m" ]] ; then
if [[ ${confMode} != "-m" ]] ; then
# try writing config directly if it doesn't exist
if [ ! -f "$dest" ] ; then
"${transferCmd}" "${source}" > "${dest}"
@@ -874,7 +895,7 @@ addConf() {
if [[ ${confMode} == "-s" ]] ; then
# if skip is selected, don't try to backup but add confilict entry
sqr::echo "skipping (exists)"
else
else
# try backup existing config
addConfBackup="${dest}_$(date +%Y%m%d-%H%M%S).bck"
if [ ! -f "${addConfBackup}" ] ; then
@@ -910,7 +931,7 @@ addConf() {
{
printf '#--- "%s" %s (Option: %s) ---' "${dest}" "${helpText}" "${confMode}"
"${transferCmd}" "${source}"
echo
echo
} >> "${sqr_missingConf}"
warning -e "Check $(realpath "${sqr_missingConf}") for configuration conflicts (${dest})"
@@ -933,7 +954,7 @@ checkStep() {
if exists "_sqr_alias_${1:-}" ; then
testRef="_sqr_alias_${1:-}"
checkStep_ref="${!testRef}"
else
else
checkStep_ref=0
fi
@@ -1439,7 +1460,7 @@ exep() {
sqr::compatible() {
if ! exists "sqr_minVersion"; then
sqr_minVersion="${VERSION_SEQREV:-0}"
fi
fi
if [ -z "${sqr_minVersion:-}" ] ; then
warning "No sequence revision found. Trying anyway..."
else