@@ -258,50 +258,31 @@ def start_terminal_interface(interpreter):
258
258
for arg in arguments :
259
259
action = arg .get ("action" , "store_true" )
260
260
nickname = arg .get ("nickname" )
261
- default = arg .get ("default" )
261
+
262
+ name_or_flags = [f'--{ arg ["name" ]} ' ]
263
+ if nickname :
264
+ name_or_flags .append (f"-{ nickname } " )
262
265
263
266
if arg ["type" ] == bool :
264
- if nickname :
265
- parser .add_argument (
266
- f"-{ nickname } " ,
267
- f'--{ arg ["name" ]} ' ,
268
- dest = arg ["name" ],
269
- help = arg ["help_text" ],
270
- action = action ,
271
- default = default ,
272
- )
273
- else :
274
- parser .add_argument (
275
- f'--{ arg ["name" ]} ' ,
276
- dest = arg ["name" ],
277
- help = arg ["help_text" ],
278
- action = action ,
279
- default = default ,
280
- )
267
+ parser .add_argument (
268
+ * name_or_flags ,
269
+ dest = arg ["name" ],
270
+ help = arg ["help_text" ],
271
+ action = action ,
272
+ default = None ,
273
+ )
281
274
else :
282
275
choices = arg .get ("choices" )
283
276
284
- if nickname :
285
- parser .add_argument (
286
- f"-{ nickname } " ,
287
- f'--{ arg ["name" ]} ' ,
288
- dest = arg ["name" ],
289
- help = arg ["help_text" ],
290
- type = arg ["type" ],
291
- choices = choices ,
292
- default = default ,
293
- nargs = arg .get ("nargs" ),
294
- )
295
- else :
296
- parser .add_argument (
297
- f'--{ arg ["name" ]} ' ,
298
- dest = arg ["name" ],
299
- help = arg ["help_text" ],
300
- type = arg ["type" ],
301
- choices = choices ,
302
- default = default ,
303
- nargs = arg .get ("nargs" ),
304
- )
277
+ parser .add_argument (
278
+ * name_or_flags ,
279
+ dest = arg ["name" ],
280
+ help = arg ["help_text" ],
281
+ type = arg ["type" ],
282
+ choices = choices ,
283
+ default = None ,
284
+ nargs = arg .get ("nargs" ),
285
+ )
305
286
306
287
args = parser .parse_args ()
307
288
@@ -313,7 +294,7 @@ def start_terminal_interface(interpreter):
313
294
open_storage_dir ("models" )
314
295
return
315
296
316
- if args .reset_profile != "NOT_PROVIDED" :
297
+ if args .reset_profile is not None and args . reset_profile != "NOT_PROVIDED" :
317
298
reset_profile (
318
299
args .reset_profile
319
300
) # This will be None if they just ran `--reset_profile`
@@ -349,7 +330,7 @@ def start_terminal_interface(interpreter):
349
330
350
331
### Apply profile
351
332
352
- interpreter = profile (interpreter , args .profile )
333
+ interpreter = profile (interpreter , args .profile or get_argument_dictionary ( arguments , "profile" )[ "default" ] )
353
334
354
335
### Set attributes on interpreter, because the arguments passed in via the CLI should override profile
355
336
@@ -418,9 +399,7 @@ def start_terminal_interface(interpreter):
418
399
def set_attributes (args , arguments ):
419
400
for argument_name , argument_value in vars (args ).items ():
420
401
if argument_value is not None :
421
- argument_dictionary = [a for a in arguments if a ["name" ] == argument_name ]
422
- if len (argument_dictionary ) > 0 :
423
- argument_dictionary = argument_dictionary [0 ]
402
+ if argument_dictionary := get_argument_dictionary (arguments , argument_name ):
424
403
if "attribute" in argument_dictionary :
425
404
attr_dict = argument_dictionary ["attribute" ]
426
405
setattr (attr_dict ["object" ], attr_dict ["attr_name" ], argument_value )
@@ -431,6 +410,12 @@ def set_attributes(args, arguments):
431
410
)
432
411
433
412
413
+ def get_argument_dictionary (arguments : list [dict ], key : str ) -> dict :
414
+ if len (argument_dictionary_list := list (filter (lambda x : x ["name" ] == key , arguments ))) > 0 :
415
+ return argument_dictionary_list [0 ]
416
+ return {}
417
+
418
+
434
419
def main ():
435
420
interpreter = OpenInterpreter (import_computer_api = True )
436
421
try :
0 commit comments