Skip to content

Commit

Permalink
Merge pull request #156 from tegonal/feature/exitIfArgIsNotArrayOrEmpty
Browse files Browse the repository at this point in the history
add exitIfArgIsNotArrayOrIsEmpty
  • Loading branch information
robstoll authored Mar 7, 2024
2 parents f2154aa + d04d16b commit 35204e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/utility/checks.doc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/utility/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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" "$#"
Expand Down

0 comments on commit 35204e2

Please sign in to comment.