forked from kubeflow/kubeflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.libsonnet
31 lines (29 loc) · 1.01 KB
/
util.libsonnet
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
{
// Convert a comma-delimited string to an array.
toArray(str)::
if std.type(str) == "string" && str != "null" && std.length(str) > 0 then
std.split(str, ",")
else [],
// Convert a comma-delimited string of "key=value" pairs into an object.
// For example,
// "key=value" => {key: "value"}
// "key1=value1,key2=value2" => {key1: "value1", key2: "value2"}
toObject(str)::
if std.type(str) == "string" && str != "null" && std.length(str) > 0 then {
[std.splitLimit(keyValue, "=", 1)[0]]: std.splitLimit(keyValue, "=", 1)[1]
for keyValue in $.toArray(str)
} else {},
// Convert non-boolean types like string,number to a boolean.
// This is primarily intended for dealing with parameters that should be booleans.
toBool:: function(x) {
result::
if std.type(x) == "boolean" then
x
else if std.type(x) == "string" then
std.asciiUpper(x) == "TRUE"
else if std.type(x) == "number" then
x != 0
else
false,
}.result,
}