Skip to content

Commit 802c72a

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

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,16 @@ function exitIfArgIsNotArray() {
125125
function exitIfArgIsNotArrayOrIsEmpty() {
126126
exitIfArgIsNotArray "$@"
127127
local -rn exitIfArgIsNotArrayOrIsEmpty_arr=$1
128-
local -r argNumberOrName=$2
129-
shift 2 || traceAndDie "could not shift by 2"
130128
if [[ ${#exitIfArgIsNotArrayOrIsEmpty_arr[@]} -lt 1 ]]; then
131-
traceAndDie "the passed argument \033[0;36m%s\033[0m is an empty array" "${!checkArgIsArray_arr}"
129+
traceAndDie "the passed argument \033[0;36m%s\033[0m is an empty array" "${!exitIfArgIsNotArrayOrIsEmpty_arr}"
130+
fi
131+
}
132+
133+
function exitIfArgIsNotArrayOrIsNonEmpty() {
134+
exitIfArgIsNotArray "$@"
135+
local -rn exitIfArgIsNotArrayOrIsNonEmpty_arr=$1
136+
if [[ ${#exitIfArgIsNotArrayOrIsNonEmpty_arr[@]} -gt 0 ]]; then
137+
traceAndDie "the passed argument \033[0;36m%s\033[0m is a non empty array" "${!exitIfArgIsNotArrayOrIsNonEmpty_arr}"
132138
fi
133139
}
134140

0 commit comments

Comments
 (0)