@@ -203,6 +203,26 @@ func processArgs(givenArgs []string, config *config, vm *jsonnet.VM) (processArg
203
203
i ++
204
204
}
205
205
206
+ handleVarVal := func (handle func (key string , val string )) error {
207
+ next := nextArg (& i , args )
208
+ name , content , err := getVarVal (next )
209
+ if err != nil {
210
+ return err
211
+ }
212
+ handle (name , content )
213
+ return nil
214
+ }
215
+
216
+ handleVarFile := func (handle func (key string , val string ), imp string ) error {
217
+ next := nextArg (& i , args )
218
+ name , content , err := getVarFile (next , imp )
219
+ if err != nil {
220
+ return err
221
+ }
222
+ handle (name , content )
223
+ return nil
224
+ }
225
+
206
226
for ; i < len (args ); i ++ {
207
227
arg := args [i ]
208
228
if arg == "-h" || arg == "--help" {
@@ -242,61 +262,37 @@ func processArgs(givenArgs []string, config *config, vm *jsonnet.VM) (processArg
242
262
}
243
263
config .evalJpath = append (config .evalJpath , dir )
244
264
} else if arg == "-V" || arg == "--ext-str" {
245
- next := nextArg (& i , args )
246
- name , content , err := getVarVal (next )
247
- if err != nil {
265
+ if err := handleVarVal (vm .ExtVar ); err != nil {
248
266
return processArgsStatusFailure , err
249
267
}
250
- vm .ExtVar (name , content )
251
268
} else if arg == "--ext-str-file" {
252
- next := nextArg (& i , args )
253
- name , content , err := getVarFile (next , "importstr" )
254
- if err != nil {
269
+ if err := handleVarFile (vm .ExtCode , "importstr" ); err != nil {
255
270
return processArgsStatusFailure , err
256
271
}
257
- vm .ExtCode (name , content )
258
272
} else if arg == "--ext-code" {
259
- next := nextArg (& i , args )
260
- name , content , err := getVarVal (next )
261
- if err != nil {
273
+ if err := handleVarVal (vm .ExtCode ); err != nil {
262
274
return processArgsStatusFailure , err
263
275
}
264
- vm .ExtCode (name , content )
265
276
} else if arg == "--ext-code-file" {
266
- next := nextArg (& i , args )
267
- name , content , err := getVarFile (next , "import" )
268
- if err != nil {
277
+ if err := handleVarFile (vm .ExtCode , "import" ); err != nil {
269
278
return processArgsStatusFailure , err
270
279
}
271
- vm .ExtCode (name , content )
272
280
} else if arg == "-A" || arg == "--tla-str" {
273
- next := nextArg (& i , args )
274
- name , content , err := getVarVal (next )
275
- if err != nil {
281
+ if err := handleVarVal (vm .TLAVar ); err != nil {
276
282
return processArgsStatusFailure , err
277
283
}
278
- vm .TLAVar (name , content )
279
284
} else if arg == "--tla-str-file" {
280
- next := nextArg (& i , args )
281
- name , content , err := getVarFile (next , "importstr" )
282
- if err != nil {
285
+ if err := handleVarFile (vm .TLACode , "importstr" ); err != nil {
283
286
return processArgsStatusFailure , err
284
287
}
285
- vm .TLACode (name , content )
286
288
} else if arg == "--tla-code" {
287
- next := nextArg (& i , args )
288
- name , content , err := getVarVal (next )
289
- if err != nil {
289
+ if err := handleVarVal (vm .TLACode ); err != nil {
290
290
return processArgsStatusFailure , err
291
291
}
292
- vm .TLACode (name , content )
293
292
} else if arg == "--tla-code-file" {
294
- next := nextArg (& i , args )
295
- name , content , err := getVarFile (next , "import" )
296
- if err != nil {
293
+ if err := handleVarFile (vm .TLACode , "import" ); err != nil {
297
294
return processArgsStatusFailure , err
298
295
}
299
- vm .TLACode (name , content )
300
296
} else if arg == "-t" || arg == "--max-trace" {
301
297
l := safeStrToInt (nextArg (& i , args ))
302
298
if l < 0 {
0 commit comments