Commit 4a510378 authored by Ted Hahn's avatar Ted Hahn
Browse files

Add a flag for extvars

parent 69c59d9f
......@@ -3,10 +3,12 @@ package cmd
import (
"bytes"
"encoding/json"
"errors"
goflag "flag"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/golang/glog"
"github.com/spf13/cobra"
......@@ -21,13 +23,15 @@ import (
)
const (
flagJpath = "jpath"
flagJpath = "jpath"
flagExtVar = "extVar"
)
var clientConfig clientcmd.ClientConfig
func init() {
RootCmd.PersistentFlags().StringP(flagJpath, "J", "", "Additional jsonnet library search path")
RootCmd.PersistentFlags().StringSliceP(flagExtVar, "V", nil, "Values of external variables")
// The "usual" clientcmd/kubectl flags
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
......@@ -76,6 +80,18 @@ func JsonnetVM(cmd *cobra.Command) (*jsonnet.VM, error) {
vm.JpathAdd(p)
}
extvars, err := flags.GetStringSlice(flagExtVar)
if err != nil {
return nil, err
}
for _, extvar := range extvars {
kv := strings.SplitN(extvar, "=", 2)
if len(kv) != 2 {
return nil, errors.New("Failed to parse extvar: missing '=' in " + extvar)
}
vm.ExtVar(kv[0], kv[1])
}
return vm, nil
}
......
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