@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"encoding/json"
5
+ "fmt"
5
6
"strings"
6
7
7
8
"github.com/rs/zerolog/log"
@@ -78,12 +79,16 @@ func cliCodeParser(fs *pflag.FlagSet) (func() map[string]string, func() map[stri
78
79
// need to use StringArray instead of StringSlice, because pflag attempts to
79
80
// parse StringSlice using the csv parser, which breaks when passing objects
80
81
extCode := fs .StringArray ("ext-code" , nil , "Set code value of extVar (Format: key=<code>)" )
82
+ extCodeFile := fs .StringArray ("ext-code-file" , nil , "Set code value of extVar from file (Format: key=filename)" )
81
83
extStr := fs .StringArrayP ("ext-str" , "V" , nil , "Set string value of extVar (Format: key=value)" )
84
+ extStrFile := fs .StringArray ("ext-str-file" , nil , "Set string value of extVar from file (Format: key=filename)" )
82
85
83
86
tlaCode := fs .StringArray ("tla-code" , nil , "Set code value of top level function (Format: key=<code>)" )
87
+ tlaCodeFile := fs .StringArray ("tla-code-file" , nil , "Set code value of top level function from file (Format: key=filename)" )
84
88
tlaStr := fs .StringArrayP ("tla-str" , "A" , nil , "Set string value of top level function (Format: key=value)" )
89
+ tlaStrFile := fs .StringArray ("tla-str-file" , nil , "Set string value of top level function from file (Format: key=filename)" )
85
90
86
- newParser := func (kind string , code , str * []string ) func () map [string ]string {
91
+ newParser := func (kind string , code , str , codeFile , strFile * []string ) func () map [string ]string {
87
92
return func () map [string ]string {
88
93
m := make (map [string ]string )
89
94
for _ , s := range * code {
@@ -107,12 +112,28 @@ func cliCodeParser(fs *pflag.FlagSet) (func() map[string]string, func() map[stri
107
112
}
108
113
m [split [0 ]] = string (js )
109
114
}
115
+
116
+ for _ , x := range []struct {
117
+ arg * []string
118
+ kind2 , imp string
119
+ }{
120
+ {arg : codeFile , kind2 : "code" , imp : "import" },
121
+ {arg : strFile , kind2 : "str" , imp : "importstr" },
122
+ } {
123
+ for _ , s := range * x .arg {
124
+ split := strings .SplitN (s , "=" , 2 )
125
+ if len (split ) != 2 {
126
+ log .Fatal ().Msgf ("%s-%s-file argument has wrong format: `%s`. Expected `key=filename`" , kind , x .kind2 , s )
127
+ }
128
+ m [split [0 ]] = fmt .Sprintf (`%s @"%s"` , x .imp , strings .ReplaceAll (split [1 ], `"` , `""` ))
129
+ }
130
+ }
110
131
return m
111
132
}
112
133
}
113
134
114
- return newParser ("ext" , extCode , extStr ),
115
- newParser ("tla" , tlaCode , tlaStr )
135
+ return newParser ("ext" , extCode , extStr , extCodeFile , extStrFile ),
136
+ newParser ("tla" , tlaCode , tlaStr , tlaCodeFile , tlaStrFile )
116
137
}
117
138
118
139
func envSettingsFlags (env * v1alpha1.Environment , fs * pflag.FlagSet ) {
0 commit comments