diff --git a/cmdarg.sh b/cmdarg.sh index b2ea4a6..e575bac 100644 --- a/cmdarg.sh +++ b/cmdarg.sh @@ -156,6 +156,19 @@ function cmdarg_parse fi } +function cmdarg_traceback +{ + # This code lifted from http://blog.yjl.im/2012/01/printing-out-call-stack-in-bash.html + local i=0 + local FRAMES=${#BASH_LINENO[@]} + # FRAMES-2 skips main, the last one in arrays + for ((i=FRAMES-2; i>=0; i--)); do + echo ' File' \"${BASH_SOURCE[i+1]}\", line ${BASH_LINENO[i]}, in ${FUNCNAME[i+1]} + # Grab the source code of the line + sed -n "${BASH_LINENO[i]}{s/^/ /;p}" "${BASH_SOURCE[i+1]}" + done +} + if [[ "${_DEFINED_CMDARG}" == "" ]]; then export _DEFINED_CMDARG=0 # Holds the final map of configuration options