|
56 | 56 | # } |
57 | 57 | # # check array with 2-tuples |
58 | 58 | # exitIfArgIsNotArrayWithTuples arr 2 "names" 1 describePair |
| 59 | +# |
| 60 | +# # returns 0 if the array was initialised (i.e. a value assigned) and non-0 otherwise |
| 61 | +# checkIsInitialisedArray arr |
59 | 62 | # } |
60 | 63 | # |
61 | 64 | # if checkCommandExists "cat"; then |
@@ -130,19 +133,30 @@ function exitIfArgIsNotArray() { |
130 | 133 | function exitIfArgIsNotArrayOrIsEmpty() { |
131 | 134 | exitIfArgIsNotArray "$@" |
132 | 135 | local -rn exitIfArgIsNotArrayOrIsEmpty_arr=$1 |
133 | | - if [[ ${#exitIfArgIsNotArrayOrIsEmpty_arr[@]} -lt 1 ]]; then |
| 136 | + # shellcheck disable=SC2310 # we are aware of that if and ! will disable set -e for checkIsInitialisedArray |
| 137 | + if ! checkIsInitialisedArray exitIfArgIsNotArrayOrIsEmpty_arr; then |
| 138 | + traceAndDie "the passed argument \033[0;36m%s\033[0m is an uninitialised array" "${!exitIfArgIsNotArrayOrIsEmpty_arr}" |
| 139 | + elif [[ ${#exitIfArgIsNotArrayOrIsEmpty_arr[@]} -lt 1 ]]; then |
134 | 140 | traceAndDie "the passed argument \033[0;36m%s\033[0m is an empty array" "${!exitIfArgIsNotArrayOrIsEmpty_arr}" |
135 | 141 | fi |
136 | 142 | } |
137 | 143 |
|
138 | 144 | function exitIfArgIsNotArrayOrIsNonEmpty() { |
139 | 145 | exitIfArgIsNotArray "$@" |
140 | 146 | local -rn exitIfArgIsNotArrayOrIsNonEmpty_arr=$1 |
141 | | - if [[ ${#exitIfArgIsNotArrayOrIsNonEmpty_arr[@]} -gt 0 ]]; then |
| 147 | + # shellcheck disable=SC2310 # we are aware of that if and ! will disable set -e for checkIsInitialisedArray |
| 148 | + if checkIsInitialisedArray exitIfArgIsNotArrayOrIsNonEmpty_arr && [[ ${#exitIfArgIsNotArrayOrIsNonEmpty_arr[@]} -gt 0 ]]; then |
142 | 149 | traceAndDie "the passed argument \033[0;36m%s\033[0m is a non empty array" "${!exitIfArgIsNotArrayOrIsNonEmpty_arr}" |
143 | 150 | fi |
144 | 151 | } |
145 | 152 |
|
| 153 | +function checkIsInitialisedArray() { |
| 154 | + if (($# != 1)); then |
| 155 | + traceAndDie "One argument needs to be passed to checkIsInitialisedArray, the array name, given \033[0;36m%s\033[0m\n" "$#" |
| 156 | + fi |
| 157 | + recursiveDeclareP "$1" | grep '(' >/dev/null |
| 158 | +} |
| 159 | + |
146 | 160 | function checkArgIsArrayWithTuples() { |
147 | 161 | if (($# != 5)); then |
148 | 162 | logError "Five arguments need to be passed to checkArgIsArrayWithTuples, given \033[0;36m%s\033[0m\n" "$#" |
|
0 commit comments