/
extravars.go
57 lines (48 loc) · 1.19 KB
/
extravars.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
package ansible
import (
"strings"
"github.com/ekara-platform/engine/util"
)
//ExtraVars extra vars, received into the buffer, to be passed to a playbook
type ExtraVars struct {
// Indicates if the struct has content or not
Bool bool
// The extra vars content
Vals []string
}
func (ev ExtraVars) String() string {
r := ""
for _, v := range ev.Vals {
r = r + " " + v
}
return r
}
//BuildExtraVars builds the extra var to pass to a playbook
func BuildExtraVars(extraVars string, inputFolder util.FolderPath, outputFolder util.FolderPath, b Buffer) ExtraVars {
r := ExtraVars{}
r.Vals = make([]string, 0)
vars := strings.Trim(extraVars, " ")
in := strings.Trim(inputFolder.Path(), " ")
out := strings.Trim(outputFolder.Path(), " ")
if vars == "" && in == "" && out == "" && len(b.Extravars) == 0 {
r.Bool = false
} else {
r.Bool = true
r.Vals = append(r.Vals, "--extra-vars")
if vars != "" {
r.Vals = append(r.Vals, vars)
}
if in != "" {
r.Vals = append(r.Vals, "input_dir="+in)
}
if out != "" {
r.Vals = append(r.Vals, "output_dir="+out)
}
if len(b.Extravars) > 0 {
for k, v := range b.Extravars {
r.Vals = append(r.Vals, k+"="+v)
}
}
}
return r
}