From f52b579b13ba2e64be5fed486b047e30e76be87f Mon Sep 17 00:00:00 2001 From: TheOnePath Date: Sun, 30 Jul 2023 16:48:58 +0100 Subject: [PATCH] Added logging to module --- soypak/cli/soypakcli.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/soypak/cli/soypakcli.py b/soypak/cli/soypakcli.py index 8c8bdcc..21ce906 100644 --- a/soypak/cli/soypakcli.py +++ b/soypak/cli/soypakcli.py @@ -1,4 +1,5 @@ import sys +import clog import soypak.cli.command as command # import all the commands to auto-register @@ -11,26 +12,35 @@ import soypak.cli.parser as parser class SoypakCLI: def __init__(self) -> None: + log = clog.Logger.get("runtime_logger") # set up the parser and parse the args + log.writeLog("Parsing CLI arguments provided.") _parser = parser.SoypakParser() cmd, args = _parser.parse_args() + log.debug("The command identified was: {}.".format(cmd)) + # check for global optional argument flags if _parser.namespace.version: + log.writeLog("The version flag was specified. Displaying the version info and exiting (0).",) print(_parser.VERSION) sys.exit(0) # if we haven't been provided a command if cmd is None: + log.error("No command has been specified.").withConsole() _parser.print_help() self.die() # fetch the command and pass arguments for initialisation + log.writeLog("Identifying if the given command specified is recognised.", level=0) self.command = command.Command.get_command(cmd, args=args) if not self.command: - print("Unrecognised command: %s" % cmd) + log.warn("Unrecognised command: %s" % cmd).withConsole() self.die() + log.debug(f"Recognised: {cmd=}. Class instance has been constructed: {self.command=} ({args=})") + def die(self): sys.exit(1)