Add option to suppress success messages

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2020-09-06 15:43:16 +02:00
parent 26653a0e01
commit 4422f1f582
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -5,6 +5,21 @@ source ${HOME}/bin/script_framework.sh
reportpad=0
retcode=0
showsuccess=1
while getopts "hq" opt; do
case "${opt}" in
q)
showsuccess=0
;;
*)
echo "Usage: $(basename $0) [-hq]"
echo " -h Show help"
echo " -q Quiet (show no success messages)"
exit 2
;;
esac
done
# report is a wrapper to display messages in a certain level with
# added information about the function yielding the result. It
@ -15,6 +30,8 @@ function report() {
local message="$@"
local func="${FUNCNAME[1]#sanity_}"
[[ $levelfunc == "success" ]] && [ $showsuccess -eq 0 ] && return || true
"$levelfunc" "$(printf "%-${reportpad}s" ${func}) ${message}"
}