Add fail on function

This commit is contained in:
Felipe Santos 2020-07-29 20:19:32 +00:00
parent 0e6247e9e9
commit 1f39b0f568

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
} }