From de6d5db3f2e9955a3493b4ea85d50da8452fa653 Mon Sep 17 00:00:00 2001 From: upuv Date: Sun, 3 Jun 2018 15:49:19 +1000 Subject: [PATCH] Enhanced DEBUG output for command line options --- AAXtoMP3 | 64 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/AAXtoMP3 b/AAXtoMP3 index 6410059..da909fb 100755 --- a/AAXtoMP3 +++ b/AAXtoMP3 @@ -63,9 +63,43 @@ if [ "$#" -eq 0 ]; then exit 1 fi +set -o errexit -o noclobber -o nounset -o pipefail + +# ======================================================================== +# Utility Functions + +# ----- +# debug +debug() { + if [ $DEBUG == 1 ] ; then + echo "$(date "+%F %T%z") DEBUG ${1}" + fi +} + +# ----- +# debug dump contents of a file to STDOUT +debug_file() { + if [ $DEBUG == 1 ] ; then + echo "$(date "+%F %T%z") DEBUG" + echo "================================================================================" + cat "${1}" + echo "================================================================================" + fi +} + +# ----- +# log +log() { + echo "$(date "+%F %T%z") ${1}" +} + +# ----- +# Print out what we have already after command line processing. +debug "Command line options as set:$(printf '\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s\n%-18s: %s' codec "${codec}" extension "${extension}" mode "${mode}" container "${container}" targetdir "${targetdir}" completedir "${completedir}" auth_code "${auth_code}")" + # ======================================================================== # Variable validation -set -o errexit -o noclobber -o nounset -o pipefail + # ----- # Detect which annoying version fo grep we have @@ -127,34 +161,6 @@ if [[ "x${completedir}" != "x" ]]; then fi fi -# ======================================================================== -# Utility Functions - -# ----- -# debug -debug() { - if [ $DEBUG == 1 ] ; then - echo "$(date "+%F %T%z") DEBUG ${1}" - fi -} - -# ----- -# debug dump contents of a file to STDOUT -debug_file() { - if [ $DEBUG == 1 ] ; then - echo "$(date "+%F %T%z") DEBUG" - echo "================================================================================" - cat "${1}" - echo "================================================================================" - fi -} - -# ----- -# log -log() { - echo "$(date "+%F %T%z") ${1}" -} - # ----- # Clean up if someone hits ^c trap 'rm -r -f "${working_directory}"' EXIT