-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathis-array-empty
executable file
·77 lines (64 loc) · 1.56 KB
/
is-array-empty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# is the array absolutely empty?
# failure if any value is truthy
# pass if all values are empty
# if you are using this in conjunction with a is-array-partial,
# or your own [[ -n ... ]] or [[ -z ... ]] calls,
# then there is no need for this
function is_array_empty() (
source "$DOROTHY/sources/bash.bash"
dorothy-warnings add --code='is-array-empty' --bold=' has been deprecated in favor of ' --code='is-whitespace'
# =====================================
# Arguments
function help {
cat <<-EOF >/dev/stderr
ABOUT:
Check if an array is entirely empty with zero non-empty elements.
USAGE:
is-array-empty [--] ...<element>
OPTIONS:
<element>
An element of the array.
RETURNS:
[0] if the array is entirely empty with zero non-empty elements.
[1] if the array is not entirely empty, having at least one non-empty element.
EOF
if [[ $# -ne 0 ]]; then
echo-error "$@"
fi
return 22 # EINVAL 22 Invalid argument
}
# process
local item option_inputs=()
while [[ $# -ne 0 ]]; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--')
option_inputs+=("$@")
shift "$#"
break
;;
'--'*) help "An unrecognised flag was provided: $item" ;;
*)
option_inputs+=("$item" "$@")
shift "$#"
break
;;
esac
done
# =====================================
# Action
local input
for input in "${option_inputs[@]}"; do
if is-not-whitespace -- "$input"; then
return 1
fi
done
return 0
)
# fire if invoked standalone
if [[ $0 == "${BASH_SOURCE[0]}" ]]; then
is_array_empty "$@"
fi