-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflag.sh
56 lines (51 loc) · 1.42 KB
/
flag.sh
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
#
#
# example:
# set_flag XXX a
# set_flag YYY b
# then check
#
# if check_flag XXX a ...
#
set_flag()
## set_flag VARIABLE FLAG
##
## enable FLAG in VARIABLE
## logicaly equivalent to VARIABLE ||= FLAG
##
## example
## check_flag modules_loaded log --> failure
## set_flag modules_loaded log
## check_flag modules_loaded log --> success
## check_flag modules_loaded foo --> success
## set_flag modules_loaded foo
## check_flag modules_loaded log --> success
## check_flag modules_loaded foo --> success
{
local name="$1"
local value="$2"
flag_old_val=$(eval echo "\$""$name")
eval "$name='$flag_old_val $value'"
}
check_flag()
## check_flag VARIABLE FLAG
##
## check if FLAG is set in VARIABLE
## logicaly equivalent to set_contains($VARIABLE,FLAG)
##
## example
## check_flag modules_loaded log --> failure
## set_flag modules_loaded log
## check_flag modules_loaded log --> success
## check_flag modules_loaded foo --> success
## set_flag modules_loaded foo
## check_flag modules_loaded log --> success
## check_flag modules_loaded foo --> success
{
local name="$1"
local tested_value="$2"
flag_val=$(eval echo "\$""$name")
echo "$flag_val" | tr ' ' '\n' | egrep -q "^$tested_value\$"
local rv=$?
return $rv
}