Skip to content

Commit 74b0de7

Browse files
committed
exitIfArgIsNotArrayOrIsNonEmpty e.g. for out array parameters
1 parent 74f543e commit 74b0de7

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/utility/checks.doc.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function foo() {
2929

3030
exitIfArgIsNotArray arr 1
3131
exitIfArgIsNotArrayOrIsEmpty arr 1
32+
exitIfArgIsNotArrayOrIsNonEmpty arr 1
3233
exitIfArgIsNotFunction "$fn" 2
3334
exitIfArgIsNotBoolean "$bool" 3
3435
exitIfArgIsNotVersion "$version" 4

src/utility/checks.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ function exitIfArgIsNotArrayOrIsEmpty() {
132132
fi
133133
}
134134

135+
function exitIfArgIsNotArrayOrIsNonEmpty() {
136+
exitIfArgIsNotArray "$@"
137+
local -rn exitIfArgIsNotArrayOrIsNonEmpty_arr=$1
138+
local -r argNumberOrName=$2
139+
shift 2 || traceAndDie "could not shift by 2"
140+
if [[ ${#exitIfArgIsNotArrayOrIsNonEmpty_arr[@]} -gt 0 ]]; then
141+
traceAndDie "the passed argument \033[0;36m%s\033[0m is a non empty array" "${!checkArgIsArray_arr}"
142+
fi
143+
}
144+
135145
function checkArgIsArrayWithTuples() {
136146
if (($# != 5)); then
137147
logError "Five arguments need to be passed to checkArgIsArrayWithTuples, given \033[0;36m%s\033[0m\n" "$#"

0 commit comments

Comments
 (0)