aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtranscode.sh44
1 files changed, 30 insertions, 14 deletions
diff --git a/transcode.sh b/transcode.sh
index 1fd1fe0..9fca292 100755
--- a/transcode.sh
+++ b/transcode.sh
@@ -196,41 +196,57 @@ readonly EXIT_OK EXIT_RUNTIME_FAILURE EXIT_USAGE_ERROR EXIT_CONFIG_ERROR EXIT_MI
# functions and runtime behaviour such as displaying usage instructions.
###############################################################################
-error() {
+emit() {
+ local prefix="$1"
+ local color="$2"
+ shift 2
+
+ if [[ $# -eq 0 ]]; then
+ printf "%b%s%b\n" "${BOLD}${color}" "$prefix" "$ALL_OFF"
+ return
+ fi
+
local mesg="$1"
shift
- printf "${BOLD}${RED}==> ERROR:${ALL_OFF} ${BOLD}%s${ALL_OFF} %s\n" "$mesg" "$@" >&2
+
+ local rest=""
+ if [[ $# -gt 0 ]]; then
+ printf -v rest ' %s' "$@"
+ rest="${rest# }"
+ fi
+
+ printf "%b%s%b %b%s%b" "${BOLD}${color}" "$prefix" "$ALL_OFF" "$BOLD" "$mesg" "$ALL_OFF"
+ if [[ -n "$rest" ]]; then
+ printf " %s" "$rest"
+ fi
+ printf "\n"
+}
+
+error() {
+ emit "==> ERROR:" "$RED" "$@" >&2
}
msg() {
if [[ $QUIET -eq 0 ]]; then
- local mesg="$1"
- shift
- printf "${BOLD}${GREEN}==>${ALL_OFF} ${BOLD}%s${ALL_OFF} %s\n" "$mesg" "$@"
+ emit "==>" "$GREEN" "$@"
fi
}
warn() {
if [[ $QUIET -eq 0 ]]; then
- local mesg="$1"
- shift
- printf "${BOLD}${YELLOW}==>${ALL_OFF} ${BOLD}%s${ALL_OFF} %s\n" "$mesg" "$@"
+ emit "==>" "$YELLOW" "$@"
fi
}
verbose() {
if [[ $VERBOSE -eq 1 && $QUIET -eq 0 ]]; then
- local mesg="$1"
- shift
- printf "${BOLD}${BLUE}==>${ALL_OFF} ${BOLD}%s${ALL_OFF} %s\n" "$mesg" "$@"
+ emit "==>" "$BLUE" "$@"
fi
}
debug() {
if [[ $DEBUG -eq 1 ]]; then
- local mesg="$1"
- shift
- printf "${BOLD}${MAGENTA}==> DEBUG:${ALL_OFF} ${BOLD}%s${ALL_OFF} %s\n" "$mesg" "$@"
+ emit "==> DEBUG:" "$MAGENTA" "$@"
fi
}