Added some basic validation

This commit is contained in:
Gnarwhal 2024-09-09 18:19:50 +00:00
parent 349a9cbd0e
commit fb79537707
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
3 changed files with 15 additions and 10 deletions

View file

@ -18,15 +18,12 @@ from sshare.plugin import Plugin
class Logger:
def __init__(self, *args, **kwargs):
if kwargs.get("command_line"):
self._loggers = [ kwargs["command_line"] ]
else:
self._loggers = []
self._loggers = []
self.add(*args)
def add(self, *args, **kwargs):
for logger in args:
self._loggers.append()
self._loggers.append(logger)
def info(self, message):
for logger in self._loggers:

View file

@ -67,9 +67,10 @@ def main():
config["config"],
config["flags"],
)
logger = Logger(command_line=command_line)
logger = Logger(command_line)
plugin_types = [ "logger", "source", "name", "upload", "location", "feedback" ]
plugins = PluginManager(
[ "logger", "source", "name", "upload", "location", "feedback" ],
plugin_types,
logger,
config["config"],
config["flags"],
@ -99,6 +100,16 @@ def main():
logger.add(*plugins.logger.active)
plugins.activate()
for plugin_type in [ "source", "name", "upload" ]:
plugins_of_type = getattr(plugins, plugin_type)
if len(plugins_of_type.active) == 0:
logger.error(f"Error: No '{plugin_type}' plugins activated. Available plugins:")
for plugin in plugins_of_type.inactive:
logger.error(f" => {plugin.name}")
sys.exit(1)
if len(plugins.location.active) == 0 and len(plugins.feedback.active) > 0:
logger.warn("Warning: 'feedback' plugins activated with no active 'location' plugins")
sources = []
for plugin in plugins.source.active:
sources.append(plugin.get_source())

View file

@ -22,9 +22,6 @@ plugin_type = "name"
config = {
"base": 62,
}
args = {
"base": Argument(help="Set the numeric base to use for the current time"),
}
def init():
if not isinstance(config.base, int):