# Path: argparser.py
# class ArgumentsParser:
#     def __init__(self, params, arguments, method):
#         if not isinstance(arguments, dict):
#             raise Exception("Command arguments is not a dict")
# 
#         self.params = params
#         self.arguments = arguments
#         self.method = method
#         self._parse()
# 
#     def _check_required(self, required, key):
#         if required == False:
#             return
# 
#         if required == True and key in self.params:
#             return
# 
#         if required == True and key not in self.params:
#             raise KeyError(f"{key} is required and was not given")
# 
#     def _parse(self):
#         for key, val in self.arguments.items():
#             if isinstance(val, dict):
#                 if "required" in val:
#                     required = val["required"]
# 
#                     if isinstance(val["required"], list) and self.method in required:
#                         self._check_required(True, key)
#                     else:
#                         self._check_required(required, key)
# 
#                 if "type" in val:
#                     type_ = val["type"]
# 
#                     if key in self.params and not isinstance(self.params[key], type_):
#                         raise TypeError(f"'{key}' is not of type '{type_}'")
# 
#                 if "default" in val and key not in self.params:
#                     self.params[key] = val["required"]
# 
#             else:
#                 if key not in self.params:
#                     self.params[key] = val
# 
#     def get_params(self):
#         return self.params
# 
# Path: util.py
# def get_version():
#     confpath = Path(PATH) / "pyproject.toml"
# 
#     with open(confpath) as f:
#         project = toml.load(f)
#         version = project["tool"]["poetry"]["version"]
#         return version


import inspect
import json
import jsonpickle
import logging
import os
import toml
from argparser import ArgumentsParser
from config import PATH
from util import get_version

        logging.info("Commands we're going to load %s" % cmddirs)

        for cmdname in cmddirs:
            logging.debug("Parsing <%s>" % cmdname)

            command = self.get(cmdname)
            commands[cmdname] = cmdname

            if hasattr(command, "aliases"):
                for alias in command.aliases:
                    commands[alias] = cmdname

            logging.info("Okay, loaded <%s>" % cmdname)

        logging.debug("Done loading")

        return commands

    def execute(self, params, cmd, cmdmethod, name):
        logging.debug("Executing command %s/%s" % (name, cmdmethod))
        logging.debug("With params " + json.dumps(params, indent = 4))

        if not hasattr(cmd, "run"):
            raise TypeError("Chantek commands required a 'run' method")

        # If there is an 'arguments' dict, use that to fill in default
        # values for the params
        if hasattr(cmd, "arguments"):
            logging.debug(f"Parsing default arguments for <{name}>")

# Path: argparser.py
# class ArgumentsParser:
#     def __init__(self, params, arguments, method):
#         if not isinstance(arguments, dict):
#             raise Exception("Command arguments is not a dict")
# 
#         self.params = params
#         self.arguments = arguments
#         self.method = method
#         self._parse()
# 
#     def _check_required(self, required, key):
#         if required == False:
#             return
# 
#         if required == True and key in self.params:
#             return
# 
#         if required == True and key not in self.params:
#             raise KeyError(f"{key} is required and was not given")
# 
#     def _parse(self):
#         for key, val in self.arguments.items():
#             if isinstance(val, dict):
#                 if "required" in val:
#                     required = val["required"]
# 
#                     if isinstance(val["required"], list) and self.method in required:
#                         self._check_required(True, key)
#                     else:
#                         self._check_required(required, key)
# 
#                 if "type" in val:
#                     type_ = val["type"]
# 
#                     if key in self.params and not isinstance(self.params[key], type_):
#                         raise TypeError(f"'{key}' is not of type '{type_}'")
# 
#                 if "default" in val and key not in self.params:
#                     self.params[key] = val["required"]
# 
#             else:
#                 if key not in self.params:
#                     self.params[key] = val
# 
#     def get_params(self):
#         return self.params
# 
# Path: util.py
# def get_version():
#     confpath = Path(PATH) / "pyproject.toml"
# 
#     with open(confpath) as f:
#         project = toml.load(f)
#         version = project["tool"]["poetry"]["version"]
#         return version


# Path: commandsmanager.py
import inspect
import json
import jsonpickle
import logging
import os
import toml
from argparser import ArgumentsParser
from config import PATH
from util import get_version


        logging.info("Commands we're going to load %s" % cmddirs)

        for cmdname in cmddirs:
            logging.debug("Parsing <%s>" % cmdname)

            command = self.get(cmdname)
            commands[cmdname] = cmdname

            if hasattr(command, "aliases"):
                for alias in command.aliases:
                    commands[alias] = cmdname

            logging.info("Okay, loaded <%s>" % cmdname)

        logging.debug("Done loading")

        return commands

    def execute(self, params, cmd, cmdmethod, name):
        logging.debug("Executing command %s/%s" % (name, cmdmethod))
        logging.debug("With params " + json.dumps(params, indent = 4))

        if not hasattr(cmd, "run"):
            raise TypeError("Chantek commands required a 'run' method")

        # If there is an 'arguments' dict, use that to fill in default
        # values for the params
        if hasattr(cmd, "arguments"):
            logging.debug(f"Parsing default arguments for <{name}>")

            parser = ArgumentsParser(params, cmd.arguments, cmdmethod)