Added logging to module
This commit is contained in:
parent
7500d5424f
commit
f52b579b13
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user