forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
var_flags.go
30 lines (23 loc) · 852 Bytes
/
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
package cmd
import (
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)"`
}
func (f VarFlags) AsVariables() boshtpl.Variables {
vars := boshtpl.Variables{}
for _, varsEnv := range f.VarsEnvs {
vars = vars.Merge(varsEnv.Vars)
}
for _, varsFile := range f.VarsFiles {
vars = vars.Merge(varsFile.Vars)
}
for _, kv := range f.VarKVs {
vars[kv.Name] = kv.Value
}
return vars
}