From 78aae5ee68347ad267a0b82ce3a582e5f9e51bd1 Mon Sep 17 00:00:00 2001 From: Lucas Caudill Date: Fri, 12 Jan 2024 11:23:30 -0700 Subject: [PATCH] PR #1802: add WARNING to base.sh --- bin/ch-convert | 2 +- lib/base.sh | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/bin/ch-convert b/bin/ch-convert index 787e01ea1..103310e6c 100755 --- a/bin/ch-convert +++ b/bin/ch-convert @@ -474,7 +474,7 @@ chimage_out_validate () { FATAL "exists in ch-image storage, not deleting per --no-clobber: ${1}" fi if [ -n "$xattrs" ]; then - WARNING "--xattrs unsupported for out format \"ch-image\"" + WARNING -- "--xattrs unsupported for out format \"ch-image\"" fi } diff --git a/lib/base.sh b/lib/base.sh index 36c746d21..3517af9e3 100644 --- a/lib/base.sh +++ b/lib/base.sh @@ -13,6 +13,17 @@ ch_lib=${ch_bin}/../lib # Python code. log_level=0 +# Logging functions. Note that we disable SC2059 because we want these functions +# to behave exactly like printf(1), e.g. we want +# +# >>> VERBOSE "foo %s" "bar" +# foo bar +# +# Implementing the suggestion in SC2059 would instead result in something like +# +# >>> VERBOSE "foo %s" "bar" +# foo %sbar + DEBUG () { if [ "$log_level" -ge 2 ]; then # shellcheck disable=SC2059 @@ -45,6 +56,15 @@ VERBOSE () { fi } +WARNING () { + if [ "$log_level" -ge -1 ]; then + printf 'warning: ' 1>&2 + # shellcheck disable=SC2059 + printf "$@" 1>&2 + printf '\n' 1>&2 + fi +} + # Return success if path $1 exists, without dereferencing links, failure # otherwise. (“test -e” dereferences.) exist_p () {