diff --git a/abcde b/abcde index 031a261..1378344 100755 --- a/abcde +++ b/abcde @@ -1497,8 +1497,8 @@ do_encode () esac ;; *) - vecho -n "DISTMP3:" - vecho "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1" + vecho -n "DISTMP3: " + vecho -c "$DISTMP3 $DISTMP3OPTS $2 $IN $OUT >/dev/null 2>&1" $RUN_COMMAND nice $DISTMP3NICE $DISTMP3 $DISTMP3OPTS "$2" "$IN" "$OUT" > /dev/null 2>&1 ;; esac @@ -2240,7 +2240,7 @@ do_discid () { SUBMITURL= if [ -z "${CDDBDISCID}" ]; then - vecho -n "Getting CD track info... " + vecho "Getting CD track info... " # In OSX, unmount the disc before a query if [ "$OSFLAVOUR" = "OSX" ]; then diskutil unmount "${CDROM#/dev/}" @@ -3120,7 +3120,7 @@ do_cddb_read () ;; 210|211) # Multiple exact, (possibly multiple) inexact matches - vecho -n "Retrieving multiple matches... " + vecho "Retrieving multiple matches... " grep -v '^[.]$' "${SOURCE_WORKDIR}/cddbquery" | ( # IN A SUB-SHELL - VARIABLES MODIFIED # HERE DO NOT PERSIST IN THE PARENT @@ -4069,28 +4069,34 @@ do_cdspeed () fi } -# vecho [message] +# vecho [-c|-n] [message] # # vecho outputs a message if EXTRAVERBOSE is 1 or more +# -c is for a continuation line, -n is for no newline vecho () { if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 0 ] ; then case $1 in warning) shift ; log warning "$@" ;; - *) >&4 echo "$@" ;; + -c) shift ; >&4 echo "$@" ;; # for a continuation line + -n) shift ; >&4 echo -n "[Verbose] $@" ;; + *) >&4 echo "[Verbose] $@" ;; esac fi } -# vvecho [message] +# vvecho [-c|-n] [message] # # vvecho outputs a message if EXTRAVERBOSE is 2 or more +# -c is for a continuation line, -n is for no newline vvecho () { if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 1 ] ; then case $1 in warning) shift ; log warning "$@" ;; - *) >&4 echo "$@" ;; + -c) shift ; >&4 echo "$@" ;; # for a continuation line + -n) shift ; >&4 echo -n "[Verbose2] $@" ;; + *) >&4 echo "[Verbose2] $@" ;; esac fi } @@ -5519,7 +5525,7 @@ if [ "$DOREAD" = "y" ]; then # User-definable function to set some things. Use it for # - closing the CD tray with eject -t # - set the CD speed value with eject -x - vecho -n "Executing customizable pre-read function... " + vecho "Executing customizable pre-read function... " pre_read # Execute the user-defined pre-read function. Close the CD with it. diff --git a/test-snippets/README b/test-snippets/README new file mode 100644 index 0000000..138f812 --- /dev/null +++ b/test-snippets/README @@ -0,0 +1,6 @@ +Directory for test code snippets + +Allows for testing individual functions, +without having to fully invoke abcde. + +Not needed/wanted as part of deployment. \ No newline at end of file diff --git a/test-snippets/log-testing.sh b/test-snippets/log-testing.sh new file mode 100755 index 0000000..9452184 --- /dev/null +++ b/test-snippets/log-testing.sh @@ -0,0 +1,64 @@ +#! /bin/bash + +# log [level] [message] +# +# log outputs the right message in a common format +log () +{ + BLURB="$1" + shift + case $BLURB in + error) >&2 echo "[ERROR] abcde: $@" >&2 ;; + warning) >&2 echo "[WARNING] $@" >&2 ;; + info) >&4 echo "[INFO] $@" ;; + console) >&4 echo "$@" ;; + esac +} + +# vecho [-c|-n] [message] +# +# vecho outputs a message if EXTRAVERBOSE is 1 or more +# -c is for a continuation line, -n is for no newline +vecho () +{ +if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 0 ] ; then + case $1 in + warning) shift ; log warning "$@" ;; + -c) shift ; >&4 echo "$@" ;; # for a continuation line + -n) shift ; >&4 echo -n "[Verbose] $@" ;; + *) >&4 echo "[Verbose] $@" ;; + esac +fi +} + +# vvecho [-c|-n] [message] +# +# vvecho outputs a message if EXTRAVERBOSE is 2 or more +# -c is for a continuation line, -n is for no newline +vvecho () +{ +if [ x"$EXTRAVERBOSE" != "x" ] && [ "$EXTRAVERBOSE" -gt 1 ] ; then + case $1 in + warning) shift ; log warning "$@" ;; + -c) shift ; >&4 echo "$@" ;; # for a continuation line + -n) shift ; >&4 echo -n "[Verbose2] $@" ;; + *) >&4 echo "[Verbose2] $@" ;; + esac +fi +} + +exec 4>&1 +EXTRAVERBOSE=$1 + +echo "testing vecho and vvecho functions" +log console "call with a number 1 or 2 to see verbose logging output" +vecho "with newline" +vecho -n "without newline: " +vecho -c "continued on the same line" + +vvecho "with newline" +vvecho -n "without newline: " +vvecho -c "continued on the same line" + +log console "testing console log -- print without prefix" +log info "testing info log -- print with [INFO] prefix"