From 859bb8000f17b99f734192c7afacb35a865e6858 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sun, 2 Feb 2025 14:01:21 +0100 Subject: [PATCH] Cmds / Cmd: Add comments and debug logging Add some comments and a little debug logging to clarify operation. Signed-off-by: Jan Lindemann --- tools/python/jwutils/Cmd.py | 2 ++ tools/python/jwutils/Cmds.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) 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):