diff --git a/src/utility/checks.doc.sh b/src/utility/checks.doc.sh index 3409c277..4a571f62 100644 --- a/src/utility/checks.doc.sh +++ b/src/utility/checks.doc.sh @@ -24,6 +24,7 @@ function foo() { checkArgIsArrayWithTuples arr 3 "names" 1 describeTriple exitIfArgIsNotArray arr 1 + exitIfArgIsNotArrayOrIsEmpty arr 1 exitIfArgIsNotFunction "$fn" 2 # shellcheck disable=SC2317 # is passed by name to exitIfArgIsNotArrayWithTuples diff --git a/src/utility/checks.sh b/src/utility/checks.sh index d86aae38..0b437b75 100644 --- a/src/utility/checks.sh +++ b/src/utility/checks.sh @@ -40,6 +40,7 @@ # checkArgIsArrayWithTuples arr 3 "names" 1 describeTriple # # exitIfArgIsNotArray arr 1 +# exitIfArgIsNotArrayOrIsEmpty arr 1 # exitIfArgIsNotFunction "$fn" 2 # # # shellcheck disable=SC2317 # is passed by name to exitIfArgIsNotArrayWithTuples @@ -106,6 +107,16 @@ function exitIfArgIsNotArray() { checkArgIsArray "$@" || exit $? } +function exitIfArgIsNotArrayOrIsEmpty() { + exitIfArgIsNotArray "$@" + local -rn exitIfArgIsNotArrayOrIsEmpty_arr=$1 + local -r argNumber=$2 + shift 2 || die "could not shift by 2" + if [[ ${#exitIfArgIsNotArrayOrIsEmpty_arr[@]} -lt 1 ]]; then + die "the passed argument \033[0;36m%s\033[0m is an empty array" "${!checkArgIsArray_arr}" + fi +} + function checkArgIsArrayWithTuples() { if ! (($# == 5)); then logError "Five arguments needs to be passed to checkArgIsArrayWithTuples, given \033[0;36m%s\033[0m\n" "$#"