22from ngcsimlib .logger import warn , info
33from ngcsimlib .utils import get_compartment_by_name , \
44 get_context , add_context , get_current_path , get_current_context , set_new_context
5- from ngcsimlib .compilers .command_compiler import dynamic_compile
5+ from ngcsimlib .compilers .command_compiler import dynamic_compile , wrap_command
66import json , os
77
88
@@ -343,7 +343,7 @@ def make_commands(self, path_to_commands_file):
343343 commands = json .load (file )
344344 for c_name , command in commands .items ():
345345 if command ['class' ] == "dynamic_compiled" :
346- self .compile_command_key (
346+ self .compile_by_key (
347347 * self .get_components (* command ['components' ]), compile_key = command ['compile_key' ], name = c_name )
348348 else :
349349 klass = load_from_path (command ['class' ])
@@ -384,7 +384,7 @@ def dynamicCommand(fn):
384384 get_current_context ().__setattr__ (fn .__name__ , fn )
385385 return fn
386386
387- def compile_command_key (self , * components , compile_key , name = None ):
387+ def compile_by_key (self , * components , compile_key , name = None ):
388388 """
389389 Compiles a given set of components with a given compile key.
390390 It will automatically add it to the context after compiling
@@ -408,3 +408,15 @@ def compile_command_key(self, *components, compile_key, name=None):
408408 self ._json_objects ['commands' ][name ] = {"class" : klass , "components" : _components , "compile_key" : compile_key }
409409 self .__setattr__ (name , cmd )
410410 return cmd , args
411+
412+
413+ def wrap_and_add_command (self , command , name = None ):
414+ """
415+ wraps a command and adds it to the context, if no name is provided it will use the command's internal name
416+
417+ Args:
418+ command: The command to wrap
419+
420+ name: The name of the command (default: None)
421+ """
422+ self .add_command (wrap_command (command ), name = name )
0 commit comments