forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
var_flags.go
53 lines (38 loc) · 1.49 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
package cmd
import (
cfgtypes "config_server/types"
boshtpl "github.com/cloudfoundry/bosh-cli/director/template"
)
// Shared
type VarFlags struct {
VarKVs []boshtpl.VarKV `long:"var" short:"v" value-name:"VAR=VALUE" description:"Set variable"`
VarsFiles []boshtpl.VarsFileArg `long:"var-file" short:"l" value-name:"PATH" description:"Load variables from a YAML file"`
VarsEnvs []boshtpl.VarsEnvArg `long:"var-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
firstToUse = append(firstToUse, f.kvsAsVars())
for i, _ := range f.VarsFiles {
firstToUse = append(firstToUse, f.VarsFiles[len(f.VarsFiles)-i-1].Vars)
}
for i, _ := range f.VarsEnvs {
firstToUse = append(firstToUse, f.VarsEnvs[len(f.VarsEnvs)-i-1].Vars)
}
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
}
func (f VarFlags) kvsAsVars() boshtpl.Variables {
vars := boshtpl.StaticVariables{}
for _, kv := range f.VarKVs {
vars[kv.Name] = kv.Value
}
return vars
}