Updated logging in command.py
This commit is contained in:
parent
11435da41b
commit
63d6c4b31c
|
|
@ -4,8 +4,7 @@ import clog
|
||||||
import soypak.cli.parser as parser
|
import soypak.cli.parser as parser
|
||||||
|
|
||||||
|
|
||||||
# partial load the logger
|
log = clog.Logger.get("runtime_logger")
|
||||||
log = lambda: clog.Logger.get("runtime_logger")
|
|
||||||
|
|
||||||
|
|
||||||
class CommandHelpStruct:
|
class CommandHelpStruct:
|
||||||
|
|
@ -35,7 +34,7 @@ class Command:
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
# Just get the logger for this one statement (:@Note: if more logging occurs, global variable for logger)
|
# 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()
|
Command.die()
|
||||||
|
|
||||||
return None
|
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)
|
# check if the command has already been given a registry name (only one should exist)
|
||||||
if hasattr(cls, 'name'):
|
if hasattr(cls, 'name'):
|
||||||
msg = f"Command {cls.__name__!r} has already been registered with the given name: {getattr(cls, 'name')!r}"
|
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)
|
raise Exception(msg)
|
||||||
|
|
||||||
# check if that registry name is already taken
|
# check if that registry name is already taken
|
||||||
if name in Command.registry_names:
|
if name in Command.registry_names:
|
||||||
msg = f"Command {cls.__name__!r} cannot use registry name {name!r} because it is in use."
|
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)
|
raise Exception(msg)
|
||||||
|
|
||||||
# set the name of the command as given
|
# 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.
|
# This is deliberate to make aware that `alias` isn't being used so pointless to pass now.
|
||||||
if alias is not None:
|
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.")
|
raise Warning("The 'alias' argument is not intended for use. Please exclude for now.")
|
||||||
|
|
||||||
# ensure that the `help` given is of the correct type
|
# ensure that the `help` given is of the correct type
|
||||||
if not isinstance(help, CommandHelpStruct):
|
if not isinstance(help, CommandHelpStruct):
|
||||||
msg = f"The argument 'help' must be of type CommandHelpStruct, not {type(help)!r}"
|
msg = f"The argument 'help' must be of type CommandHelpStruct, not {type(help)!r}"
|
||||||
log().error(msg)
|
log.error(msg)
|
||||||
raise TypeError(msg)
|
raise TypeError(msg)
|
||||||
|
|
||||||
# construct the help message
|
# construct the help message
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user