From 1f39b0f568021a771044b5d471e258e3a4417883 Mon Sep 17 00:00:00 2001 From: Felipe Santos Date: Wed, 29 Jul 2020 20:19:32 +0000 Subject: [PATCH] Add fail on function --- mo | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mo b/mo index 1ae7707..c758775 100755 --- a/mo +++ b/mo @@ -155,7 +155,7 @@ mo() ( # # Returns nothing. moCallFunction() { - local moArgs moFunctionArgs + local moArgs moFunctionArgs moFunctionResult moArgs=() moTrimWhitespace moFunctionArgs "$3" @@ -166,6 +166,12 @@ moCallFunction() { fi 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 }