Updated logging in command.py

This commit is contained in:
Ethan Smith-Coss 2023-08-07 14:42:59 +01:00
parent 11435da41b
commit 63d6c4b31c
Signed by: TheOnePath
GPG Key ID: 4E7D436CE1A0BAF1

View File

@ -4,8 +4,7 @@ import clog
import soypak.cli.parser as parser
# partial load the logger
log = lambda: clog.Logger.get("runtime_logger")
log = clog.Logger.get("runtime_logger")
class CommandHelpStruct:
@ -35,7 +34,7 @@ class Command:
if error:
# Just get the logger for this one statement (:@Note: if more logging occurs, global variable for logger)
log().error("Unrecognised command: %s" % name).withConsole()
log.error("Unrecognised command: %s" % name).withConsole()
Command.die()
return None
@ -60,13 +59,13 @@ def register_command(_cls=None, *, name: str, alias=None, help: CommandHelpStruc
# check if the command has already been given a registry name (only one should exist)
if hasattr(cls, 'name'):
msg = f"Command {cls.__name__!r} has already been registered with the given name: {getattr(cls, 'name')!r}"
log().error(msg)
log.error(msg)
raise Exception(msg)
# check if that registry name is already taken
if name in Command.registry_names:
msg = f"Command {cls.__name__!r} cannot use registry name {name!r} because it is in use."
log().error(msg)
log.error(msg)
raise Exception(msg)
# set the name of the command as given
@ -74,13 +73,13 @@ def register_command(_cls=None, *, name: str, alias=None, help: CommandHelpStruc
# This is deliberate to make aware that `alias` isn't being used so pointless to pass now.
if alias is not None:
log().warn(f"'alias' argument was passed as something other than None. This is intended for future use.")
log.warn(f"'alias' argument was passed as something other than None. This is intended for future use.")
raise Warning("The 'alias' argument is not intended for use. Please exclude for now.")
# ensure that the `help` given is of the correct type
if not isinstance(help, CommandHelpStruct):
msg = f"The argument 'help' must be of type CommandHelpStruct, not {type(help)!r}"
log().error(msg)
log.error(msg)
raise TypeError(msg)
# construct the help message