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 <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-02-23 09:21:34 +01:00
commit a160555596

View file

@ -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[^.]'))