-
Notifications
You must be signed in to change notification settings - Fork 24
/
functions
74 lines (63 loc) · 1.54 KB
/
functions
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
#!/bin/sh
__sm.variables.are.nonempty()
{
trace_filter variables || set -o xtrace
local _variable _variables
_variables=("$@")
(( $# )) && shift || __sm.log.fail "Cannot check if variables are nonempty; No variables were given."
for _variable in "${_variables[@]}"
do
eval "[[ -n \"\${${_variable}:-}\" ]]" || return 1
done
return 0
}
__sm.variables.are.empty()
{
trace_filter variables || set -o xtrace
local _variable
_variable="${1:-}"
(( $# )) && shift || __sm.log.fail "Cannot check if variable is empty, as no variable was given."
eval "[[ -z \"\${${_variable}:-}\" ]]"
}
__sm.variables.filter()
{
trace_filter variables || set -o xtrace
__sm_variables_empty=()
__sm_variables_nonempty=()
local _variable
for _variable in "$@"
do
if eval "[[ -z \"\${${_variable}:-}\" ]]"
then
__sm_variables_empty+=( "${_variable}" )
else
__sm_variables_nonempty+=( "${_variable}" )
fi
done
}
__sm.variables.must.be.nonempty()
{
trace_filter variables || set -o xtrace
local _error IFS
_error="$1"
IFS=','
shift
__sm.variables.filter "$@"
if (( ${#__sm_variables_empty[@]} ))
then
${_error} "Variables '${__sm_variables_empty[@]}' are suposed to be not empty but are not."
fi
}
__sm.variables.must.be.empty()
{
trace_filter variables || set -o xtrace
local _error IFS
_error="$1"
IFS=','
shift
__sm.variables.filter "$@"
if (( ${#__sm_variables_nonempty[@]} ))
then
${_error} "Variables '${__sm_variables_nonempty[@]}' are suposed to be empty but are not."
fi
}