#!/bin/bash #set -e APP_SVNID='$HeadURL$ $LastChangedRevision$' . $(ade-config ade_share_prefix)/include/ade.sh || { echo "${0##*/}: INTERNAL ERROR: failed to load ade.sh" >&2; exit 3; } ADESHF_DEFINED_ERRORS=( "KEY=ADESHF_ERR_MISC; FMT=\"%s\"" ) adeshf() { local OPTVAL RC TEMP ERRSTACK_REF CODE local -a DOLLARAT ERRSTACK_REF="$1" shift # Register application-specific errors ade_err_registerdefderrs ADESHF_DEFINED_ERRORS # Register adeshf's options (none) #ade_opt_register "$ERRSTACK_REF" -o f: --longoptions=op-mode:,alert: --callback-template="adeshf_opt_handler_%s" || return $? ade_msg_register "$ERRSTACK_REF" adeshf_usage_help adeshf_version adeshf_listpaths || return $? # Process options ade_opt_process "$ERRSTACK_REF" NEW_DOLLAR_AT "$@" || return $? set -- "${NEW_DOLLAR_AT[@]}" # Argument processing [ "X$1" != X -a "X$2" = X ] || ade_msg_usage_bad "$ERRSTACK_REF" CODE="$1" # Guts ade_err_debug "$ERRSTACK_REF" 10 "main: calling \"$CODE\" ..." # Use eval to run the code, but do it in a function context, so that the # code is allowed to return without making adeshf() itself return. RC=0; eval "adeshf_code_wrapper() { $CODE; }; adeshf_code_wrapper" || RC=$? # The eval returning 2 isn't a guarantee that the code failed to run: it # could have run but returned 2. We'll ignore that possibility for the # moment. if [ $RC = 2 ]; then ade_err_error "$ERRSTACK_REF" ADESHF_ERR_MISC "code failed to run; the error was displayed above" return $ADE_ERR_FAIL # Having got the syntax-error-in-code-made-eval-itself-return-failure case out # of the way, then we can examine the return code, assuming the return code # was returned by the code and not be the eval. elif [ $RC = $ADE_ERR_OK ]; then return $RC elif [ $RC = $ADE_ERR_FAIL ]; then ade_err_error "$ERRSTACK_REF" ADESHF_ERR_MISC "code ran but returned failure" return $RC else ade_err_error "$ERRSTACK_REF" ADESHF_ERR_MISC "code ran but returned a non-compliant return code; the return code was: $RC" return $ADE_ERR_FAIL fi return $ADE_ERR_OK } adeshf_usage_help() { local ERRSTACK_REF="$1"; shift local USAGE_TEXT_SHORT_REF="$1"; shift local USAGE_TEXT_LONG_REF="$1"; shift eval "$USAGE_TEXT_SHORT_REF=\"\"" eval "$USAGE_TEXT_LONG_REF=" return $ADE_ERR_OK } adeshf_listpaths() { local ERRSTACK_REF="$1"; shift local PATHLIST_REF=$1; shift eval "$PATHLIST_REF=\"\ \"" return $ADE_ERR_OK } adeshf_version() { local ERRSTACK_REF="$1"; shift local VERSION_REF=$1; shift ade_smf_extractversionfromsvnstring "$ERRSTACK_REF" "$APP_SVNID" "$VERSION_REF" return $ADE_ERR_OK } ade_gep_main adeshf "$@"