summaryrefslogtreecommitdiffhomepage
path: root/scripts/utils.sh
blob: b01aae27b0d83f5684b40e4f38ef49875e934162 (plain)
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
append() {
	local var="$1"
	local value="$2"
	local sep="${3:- }"

	eval "export -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
}

add_default_handler() {
	case "$(type $1 2>/dev/null)" in
		*function*) return;;
		*) eval "$1() { return; }"
	esac
}

_config_add_generic() {
	json_add_array ""
	json_add_string "" "$1"
	json_add_int "" "$2"
	json_close_array
}

config_add_int() {
	_config_add_generic "$1" 5
}

config_add_array() {
	_config_add_generic "$1" 1
}

config_add_string() {
	_config_add_generic "$1" 3
}

config_add_boolean() {
	_config_add_generic "$1" 7
}