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