huge refactor of plugin system
This commit is contained in:
+8
-3
@@ -28,15 +28,20 @@ def _register_cmdlet_object(cmdlet_obj, registry: Dict[str, CmdletFn]) -> None:
|
||||
registry[alias.replace("_", "-").lower()] = run_fn
|
||||
|
||||
|
||||
def register_native_commands(registry: Dict[str, CmdletFn]) -> None:
|
||||
"""Import native command modules and register their CMDLET exec functions."""
|
||||
def _iter_legacy_native_module_names() -> list[str]:
|
||||
base_dir = os.path.dirname(__file__)
|
||||
module_names: list[str] = []
|
||||
for filename in os.listdir(base_dir):
|
||||
if not (filename.endswith(".py") and not filename.startswith("_")
|
||||
and filename != "__init__.py"):
|
||||
continue
|
||||
module_names.append(filename[:-3])
|
||||
return module_names
|
||||
|
||||
mod_name = filename[:-3]
|
||||
|
||||
def register_native_commands(registry: Dict[str, CmdletFn]) -> None:
|
||||
"""Import legacy local command modules from cmdnat/ and register them."""
|
||||
for mod_name in _iter_legacy_native_module_names():
|
||||
try:
|
||||
module = import_module(f".{mod_name}", __name__)
|
||||
cmdlet_obj = getattr(module, "CMDLET", None)
|
||||
|
||||
Reference in New Issue
Block a user