@@ -37,7 +37,10 @@ def __init__(
3737 self ._exit = exit_on_failure
3838
3939 def _setup_context (
40- self , base_directory : str , options : Optional [Namespace ], plugins : Optional [List [Type [Plugin ]]]
40+ self ,
41+ base_directory : str ,
42+ options : Optional [Namespace ],
43+ plugins : Optional [List [Type [Plugin ]]],
4144 ) -> None :
4245 path = os .path .abspath (os .path .expanduser (base_directory ))
4346 if not os .path .exists (path ):
@@ -62,6 +65,7 @@ def dispatch(self, tasks: List[Dict[str, Any]]) -> bool:
6265 self ._context .set_defaults (task [action ]) # replace, not update
6366 handled = True
6467 # keep going, let other plugins handle this if they want
68+
6569 for plugin in self ._plugins :
6670 if plugin .can_handle (action ):
6771 try :
@@ -76,14 +80,25 @@ def dispatch(self, tasks: List[Dict[str, Any]]) -> bool:
7680 self ._log .error (f"An error was encountered while executing action { action } " )
7781 self ._log .debug (str (err ))
7882 if self ._exit :
79- # There was an execption exit
83+ # There was an exception exit
8084 return False
85+
86+ if action == "plugins" :
87+ # Create a list of loaded plugin names
88+ loaded_plugins = [type (plugin ).__name__ for plugin in self ._plugins ]
89+
90+ # Load plugins that haven't been loaded yet
91+ for plugin_subclass in Plugin .__subclasses__ ():
92+ if type (plugin_subclass ).__name__ not in loaded_plugins :
93+ self ._plugins .append (plugin_subclass (self ._context ))
94+
8195 if not handled :
8296 success = False
8397 self ._log .error (f"Action { action } not handled" )
8498 if self ._exit :
8599 # Invalid action exit
86100 return False
101+
87102 return success
88103
89104
0 commit comments