cmdarg_traceback prints LASTERR now

This commit is contained in:
2013-07-09 09:20:33 -04:00
parent e10acfbd05
commit a049ad7921

View File

@@ -16,7 +16,6 @@ function cmdarg
# the argument value is invalid. Can be straight bash, but it really # the argument value is invalid. Can be straight bash, but it really
# should be the name of a function. This may be enforced in future versions # should be the name of a function. This may be enforced in future versions
# of the library. # of the library.
set -u
shortopt=${1:0:1} shortopt=${1:0:1}
if [[ "${1:1:2}" == ":" ]]; then if [[ "${1:1:2}" == ":" ]]; then
CMDARG_FLAGS[$shortopt]=$CMDARG_FLAG_WITHARG CMDARG_FLAGS[$shortopt]=$CMDARG_FLAG_WITHARG
@@ -35,7 +34,6 @@ function cmdarg
cmdarg_cfg["$2"]="${4:-}" cmdarg_cfg["$2"]="${4:-}"
CMDARG_VALIDATORS["$shortopt"]="${5:-}" CMDARG_VALIDATORS["$shortopt"]="${5:-}"
CMDARG_GETOPTLIST="${CMDARG_GETOPTLIST}$1" CMDARG_GETOPTLIST="${CMDARG_GETOPTLIST}$1"
set +u
} }
function cmdarg_info function cmdarg_info
@@ -133,13 +131,11 @@ function cmdarg_parse
shortopt=${CMDARG_REV[$opt]} shortopt=${CMDARG_REV[$opt]}
if [ "${CMDARG_VALIDATORS[$shortopt]}" != "" ]; then if [ "${CMDARG_VALIDATORS[$shortopt]}" != "" ]; then
OPTARG=${cmdarg_cfg[$opt]} OPTARG=${cmdarg_cfg[$opt]}
set +e
( eval "${CMDARG_VALIDATORS[${shortopt}]}" && [ "$OPTARG" != "" ]) ( eval "${CMDARG_VALIDATORS[${shortopt}]}" && [ "$OPTARG" != "" ])
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Invalid value for -$shortopt : ${cmdarg_cfg[$opt]}" echo "Invalid value for -$shortopt : ${cmdarg_cfg[$opt]}"
failed=1 failed=1
fi fi
set -e
fi fi
done done
if [ $failed -eq 1 ]; then if [ $failed -eq 1 ]; then
@@ -162,11 +158,13 @@ function cmdarg_traceback
local i=0 local i=0
local FRAMES=${#BASH_LINENO[@]} local FRAMES=${#BASH_LINENO[@]}
# FRAMES-2 skips main, the last one in arrays # FRAMES-2 skips main, the last one in arrays
for ((i=FRAMES-2; i>=0; i--)); do for ((i=FRAMES-2; i>=1; i--)); do
echo ' File' \"${BASH_SOURCE[i+1]}\", line ${BASH_LINENO[i]}, in ${FUNCNAME[i+1]} echo ' File' \"${BASH_SOURCE[i+1]}\", line ${BASH_LINENO[i]}, probably in ${FUNCNAME[i+1]} >&2
# Grab the source code of the line # Grab the source code of the line
sed -n "${BASH_LINENO[i]}{s/^/ /;p}" "${BASH_SOURCE[i+1]}" sed -n "${BASH_LINENO[i]}{s/^/ /;p}" "${BASH_SOURCE[i+1]}" >&2
done done
echo " Error: $LASTERR"
unset FRAMES
} }
if [[ "${_DEFINED_CMDARG}" == "" ]]; then if [[ "${_DEFINED_CMDARG}" == "" ]]; then