From a160555596e1defd8527ae34ea0bc355c0db57f3 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Mon, 23 Feb 2026 09:21:34 +0100 Subject: [PATCH] jw.pkg.cmds.Cmd._add_subcommands(): Generic detection Deduce module search path for the calling module's subcommands directly from the module path of the calling module. That's more generic than the previous detection algorithm, because it recursively works for subcommands of subcommands as well. Signed-off-by: Jan Lindemann --- src/python/jw/pkg/cmds/Cmd.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/python/jw/pkg/cmds/Cmd.py b/src/python/jw/pkg/cmds/Cmd.py index 49364839..783886ae 100644 --- a/src/python/jw/pkg/cmds/Cmd.py +++ b/src/python/jw/pkg/cmds/Cmd.py @@ -14,9 +14,7 @@ class Cmd(Base): # export super().__init__(parent, name, help) def _add_subcommands(self) -> None: - self.add_subcommands( - LoadTypes( - [__name__.rsplit('.', 1)[0] + '.' + self.name], - type_name_filter=r'Cmd[^.]' - ) - ) + # Derive module search path for the calling module's subcommands from + # the module path of the calling module itself + cmds_module = type(self).__module__.replace('Cmd', '').lower() + self.add_subcommands(LoadTypes([cmds_module], type_name_filter=r'Cmd[^.]'))