diff --git a/src/python/jw/pkg/lib/Cmd.py b/src/python/jw/pkg/lib/Cmd.py index 51fea68f..dc7147ad 100644 --- a/src/python/jw/pkg/lib/Cmd.py +++ b/src/python/jw/pkg/lib/Cmd.py @@ -88,7 +88,15 @@ class AbstractCmd(abc.ABC): self, cmds: Cmd | list[Cmd] | Types[Any] | list[Types[Any]] ) -> None: if isinstance(cmds, Cmd): - raise NotImplementedError('Single Cmd should be handled elsewhere') + if any(child.name == cmds.name for child in self.__children): + raise Exception( + f'Can\'t register subcommand with already taken name "{cmds.name}"' + ) + self.__child_classes.append(type(cmds)) + cmds.set_parent(self) + self.__children.append(cmds) + assert len(self.__children) == len(self.__child_classes) + return if isinstance(cmds, list): for cmd in cmds: self.add_subcommands(cmd)