-
Notifications
You must be signed in to change notification settings - Fork 161
/
var_flags.go
60 lines (45 loc) · 1.67 KB
/
var_flags.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
package opts
import (
cfgtypes "github.com/cloudfoundry/config-server/types"
boshtpl "github.com/cloudfoundry/bosh-cli/v7/director/template"
)
// Shared
type VarFlags struct {
VarKVs []boshtpl.VarKV `long:"var" short:"v" value-name:"VAR=VALUE" description:"Set variable"`
VarFiles []boshtpl.VarFileArg `long:"var-file" value-name:"VAR=PATH" description:"Set variable to file contents"`
VarsFiles []boshtpl.VarsFileArg `long:"vars-file" short:"l" value-name:"PATH" description:"Load variables from a YAML file"`
VarsEnvs []boshtpl.VarsEnvArg `long:"vars-env" value-name:"PREFIX" description:"Load variables from environment variables (e.g.: 'MY' to load MY_var=value)"`
VarsFSStore VarsFSStore `long:"vars-store" value-name:"PATH" description:"Load/save variables from/to a YAML file"`
}
func (f VarFlags) AsVariables() boshtpl.Variables {
var firstToUse []boshtpl.Variables
staticVars := boshtpl.StaticVariables{}
for i := range f.VarsEnvs {
for k, v := range f.VarsEnvs[i].Vars {
staticVars[k] = v
}
}
for i := range f.VarsFiles {
for k, v := range f.VarsFiles[i].Vars {
staticVars[k] = v
}
}
for i := range f.VarFiles {
for k, v := range f.VarFiles[i].Vars {
staticVars[k] = v
}
}
for _, kv := range f.VarKVs {
staticVars[kv.Name] = kv.Value
}
firstToUse = append(firstToUse, staticVars)
store := &f.VarsFSStore
if f.VarsFSStore.IsSet() {
firstToUse = append(firstToUse, store)
}
vars := boshtpl.NewMultiVars(firstToUse)
if f.VarsFSStore.IsSet() {
store.ValueGeneratorFactory = cfgtypes.NewValueGeneratorConcrete(NewVarsCertLoader(vars))
}
return vars
}