diff --git a/tools/python/jwutils/Cmd.py b/tools/python/jwutils/Cmd.py index e8a080f..a05181d 100644 --- a/tools/python/jwutils/Cmd.py +++ b/tools/python/jwutils/Cmd.py @@ -49,5 +49,7 @@ class Cmd(ABC): # export return self.child_classes.append(cmd) + # To be overriden by derived class in case the command does take arguments. + # Will be called from App base class constructor and set up the parser hierarchy def add_arguments(self, parser: ArgumentParser) -> None: pass diff --git a/tools/python/jwutils/Cmds.py b/tools/python/jwutils/Cmds.py index 5b33735..293d87d 100644 --- a/tools/python/jwutils/Cmds.py +++ b/tools/python/jwutils/Cmds.py @@ -15,7 +15,11 @@ from jwutils.log import * class Cmds: # export def __instantiate(self, cls): - r = cls() + try: + r = cls() + except Exception as e: + slog(ERR, f'Failed to instantiate command of type {cls}: {e}') + raise r.cmds = self # TODO: Rename Cmds class to App, "Cmds" isn't very self-explanatory r.app = self return r @@ -86,6 +90,7 @@ class Cmds: # export cmds = [cmd for cmd in self.__cmds if type(cmd) not in subcmds] subparsers = self.__parser.add_subparsers(title='Available commands', metavar='') for cmd in cmds: + slog(DEBUG, f'Adding top-level command {cmd} to parser') self.__add_cmd_to_parser(cmd, subparsers) async def __run(self, argv=None):