Make add info() log_warn_die.sh and make the subs respect OPT_VERBOSE. Add more test harness subs in util/test-bash-functions.

This commit is contained in:
Daniel Nichter
2013-01-24 09:17:19 -07:00
parent 9693f73e5e
commit 98ced1a035
3 changed files with 125 additions and 7 deletions

View File

@@ -27,24 +27,34 @@ set -u
PTFUNCNAME=""
PTDEBUG="${PTDEBUG:-""}"
EXIT_STATUS=0
OPT_VERBOSE=${OPT_VERBOSE:-3}
log() {
TS=$(date +%F-%T | tr ':-' '_');
_print() {
TS=$(date +%F-%T | tr ':-' '_')
echo "$TS $*"
}
info() {
[ ${OPT_VERBOSE:-0} -ge 3 ] && _print "$*"
}
log() {
[ ${OPT_VERBOSE:-0} -ge 2 ] && _print "$*"
}
warn() {
log "$*" >&2
[ ${OPT_VERBOSE:-0} -ge 1 ] && _print "$*" >&2
EXIT_STATUS=1
}
die() {
warn "$*"
_print "$*" >&2
EXIT_STATUS=1
exit 1
}
_d () {
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(log "$*")" >&2
[ "$PTDEBUG" ] && echo "# $PTFUNCNAME: $(_print "$*")" >&2
}
# ###########################################################################