Merge pull request #39 from felipecassiors/felipecassiors/fail-on-function

Add fail on function
This commit is contained in:
Tyler Akins 2020-08-05 11:27:50 -08:00 committed by GitHub
commit 8cd67fb908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

8
mo
View File

@ -155,7 +155,7 @@ mo() (
# #
# Returns nothing. # Returns nothing.
moCallFunction() { moCallFunction() {
local moArgs moFunctionArgs local moArgs moFunctionArgs moFunctionResult
moArgs=() moArgs=()
moTrimWhitespace moFunctionArgs "$3" moTrimWhitespace moFunctionArgs "$3"
@ -166,6 +166,12 @@ moCallFunction() {
fi fi
echo -n "$2" | MO_FUNCTION_ARGS="$moFunctionArgs" eval "$1" "$moArgs" echo -n "$2" | MO_FUNCTION_ARGS="$moFunctionArgs" eval "$1" "$moArgs"
moFunctionResult=$?
if [[ -n "${MO_FAIL_ON_FUNCTION-}" && "$moFunctionResult" != 0 ]]; then
echo "Function '$1' with args '${moArgs@}' failed with status code $moFunctionResult"
exit $moFunctionResult
fi
} }