Skip to content

Commit

Permalink
Add support for jsonnet cli arguments --[tla|ext]-[code|str]-file
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Mogensen committed Apr 26, 2023
1 parent fd246e3 commit fad3cc6
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions cmd/tk/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ func cliCodeParser(fs *pflag.FlagSet) (func() map[string]string, func() map[stri
tlaCode := fs.StringArray("tla-code", nil, "Set code value of top level function (Format: key=<code>)")
tlaStr := fs.StringArrayP("tla-str", "A", nil, "Set string value of top level function (Format: key=value)")

newParser := func(kind string, code, str *[]string) func() map[string]string {
extCodeFile := fs.StringArray("ext-code-file", nil, "Read code value of extVar from file (Format: key=<file>)")
extStrFile := fs.StringArray("ext-str-file", nil, "Read string value of extVar from file (Format: key=<file>)")

tlaCodeFile := fs.StringArray("tla-code-file", nil, "Read code value of top level function from file (Format: key=<file>)")
tlaStrFile := fs.StringArray("tla-str=file", nil, "Read string value of top level function from file (Format: key=<file>)")

newParser := func(kind string, code, str, codeFile, strFile *[]string) func() map[string]string {
return func() map[string]string {
m := make(map[string]string)
for _, s := range *code {
Expand All @@ -95,12 +101,29 @@ func cliCodeParser(fs *pflag.FlagSet) (func() map[string]string, func() map[stri
}
m[split[0]] = fmt.Sprintf(`"%s"`, split[1])
}

for _, s := range *codeFile {
split := strings.SplitN(s, "=", 2)
if len(split) != 2 {
log.Fatal().Msgf(kind+"-code-file argument has wrong format: `%s`. Expected `key=<file>`", s)
}
m[split[0]] = fmt.Sprintf("%s @'%s'", "import", strings.Replace(split[1], "'", "''", -1))
}

for _, s := range *strFile {
split := strings.SplitN(s, "=", 2)
if len(split) != 2 {
log.Fatal().Msgf(kind+"-str-file argument has wrong format: `%s`. Expected `key=<file>`", s)
}
m[split[0]] = fmt.Sprintf("%s @'%s'", "importstr", strings.Replace(split[1], "'", "''", -1))
}

return m
}
}

return newParser("ext", extCode, extStr),
newParser("tla", tlaCode, tlaStr)
return newParser("ext", extCode, extStr, extCodeFile, extStrFile),
newParser("tla", tlaCode, tlaStr, tlaCodeFile, tlaStrFile)
}

func envSettingsFlags(env *v1alpha1.Environment, fs *pflag.FlagSet) {
Expand Down

0 comments on commit fad3cc6

Please sign in to comment.