Commit 41c5f010 authored by Thomas Hahn's avatar Thomas Hahn
Browse files

Top level arguments. Not yet implemented in go-jsonnet

parent 984254e7
......@@ -27,6 +27,8 @@ const (
flagJpath = "jpath"
flagExtVar = "ext-str"
flagExtVarFile = "ext-str-file"
flagTlaVar = "tla-str"
flagTlaVarFile = "tla-str-file"
flagResolver = "resolve-images"
flagResolvFail = "resolve-images-error"
)
......@@ -37,6 +39,8 @@ func init() {
RootCmd.PersistentFlags().StringP(flagJpath, "J", "", "Additional jsonnet library search path")
RootCmd.PersistentFlags().StringSliceP(flagExtVar, "V", nil, "Values of external variables")
RootCmd.PersistentFlags().StringSlice(flagExtVarFile, nil, "Read external variable from a file")
RootCmd.PersistentFlags().StringSliceP(flagTlaVar, "A", nil, "Values of top level arguments")
RootCmd.PersistentFlags().StringSlice(flagTlaVarFile, nil, "Read top level argument from a file")
RootCmd.PersistentFlags().String(flagResolver, "noop", "Change implementation of resolveImage native function. One of: noop, registry")
RootCmd.PersistentFlags().String(flagResolvFail, "warn", "Action when resolveImage fails. One of ignore,warn,error")
......@@ -122,6 +126,41 @@ func JsonnetVM(cmd *cobra.Command) (*jsonnet.VM, error) {
vm.ExtVar(kv[0], string(v))
}
tlavars, err := flags.GetStringSlice(flagTlaVar)
if err != nil {
return nil, err
}
for _, tlavar := range tlavars {
kv := strings.SplitN(tlavar, "=", 2)
switch len(kv) {
case 1:
v, present := os.LookupEnv(kv[0])
if present {
vm.TlaVar(kv[0], v)
} else {
return nil, fmt.Errorf("Missing environment variable: %s", kv[0])
}
case 2:
vm.TlaVar(kv[0], kv[1])
}
}
tlavarfiles, err := flags.GetStringSlice(flagTlaVarFile)
if err != nil {
return nil, err
}
for _, tlavar := range tlavarfiles {
kv := strings.SplitN(tlavar, "=", 2)
if len(kv) != 2 {
return nil, fmt.Errorf("Failed to parse tla-str-file: missing '=' in %s", tlavar)
}
v, err := ioutil.ReadFile(kv[1])
if err != nil {
return nil, err
}
vm.TlaVar(kv[0], string(v))
}
resolver, err := buildResolver(cmd)
if err != nil {
return nil, err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment