summaryrefslogtreecommitdiffhomepage
path: root/scripts/utils.sh
blob: a5dc782bfd4363340a5419341a7f27e2cbf7d3eb (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
38
39
40
41
42
43
44
45
46
47
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
}

set_default() {
	local __s_var="$1"
	local __s_val="$2"
	eval "export -- \"$__s_var=\${$__s_var:-\$__s_val}\""
}

_config_add_generic() {
	local type="$1"; shift

	for name in "$@"; do
		json_add_array ""
		json_add_string "" "$name"
		json_add_int "" "$type"
		json_close_array
	done
}

config_add_int() {
	_config_add_generic 5 "$@"
}

config_add_array() {
	_config_add_generic 1 "$@"
}

config_add_string() {
	_config_add_generic 3 "$@"
}

config_add_boolean() {
	_config_add_generic 7 "$@"
}