-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
100 lines (84 loc) · 1.64 KB
/
utils.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package darius
func CreateTask(task interface{}) map[interface{}]interface{} {
mapping, ok := task.(map[interface{}]interface{})
if ok {
return mapping
}
return map[interface{}]interface{}{"command": task}
}
func ExpandTask(
state State,
task map[interface{}]interface{},
) error {
var err error
var ok bool
_, ok = task["name"]
if ok {
task["name"], err = state.Expand(task["name"], true)
if err != nil {
return err
}
}
_, ok = task["host"]
if ok {
task["host"], err = state.Expand(task["host"], true)
if err != nil {
return err
}
}
_, ok = task["context"]
if ok {
task["context"], err = state.Expand(task["context"], false)
if err != nil {
return err
}
}
_, ok = task["job"]
if ok {
task["job"], err = state.Expand(task["job"], false)
if err != nil {
return err
}
}
_, ok = task["command"]
if ok {
task["command"], err = state.Expand(task["command"], false)
if err != nil {
return err
}
}
_, ok = task["rescue"]
if ok {
task["rescue"], err = state.Expand(task["rescue"], false)
if err != nil {
return err
}
}
_, ok = task["ensure"]
if ok {
task["ensure"], err = state.Expand(task["ensure"], false)
if err != nil {
return err
}
}
return nil
}
func Copy(value interface{}) interface{} {
mapping, ok := value.(map[interface{}]interface{})
if ok {
result := map[interface{}]interface{}{}
for key, value := range mapping {
result[key] = Copy(value)
}
return result
}
array, ok := value.([]interface{})
if ok {
result := make([]interface{}, len(array))
for index, value := range array {
result[index] = Copy(value)
}
return result
}
return value
}