From fb7953770737d8e4446e7f1bd5e835c634d861ed Mon Sep 17 00:00:00 2001 From: Gnarwhal Date: Mon, 9 Sep 2024 18:19:50 +0000 Subject: [PATCH] Added some basic validation --- src/sshare/logger.py | 7 ++----- src/sshare/main.py | 15 +++++++++++++-- src/sshare/plugins/default/current_time.py | 3 --- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/sshare/logger.py b/src/sshare/logger.py index 7901d4c..60d804c 100644 --- a/src/sshare/logger.py +++ b/src/sshare/logger.py @@ -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: diff --git a/src/sshare/main.py b/src/sshare/main.py index cb0812d..dd071ac 100644 --- a/src/sshare/main.py +++ b/src/sshare/main.py @@ -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()) diff --git a/src/sshare/plugins/default/current_time.py b/src/sshare/plugins/default/current_time.py index 03c1692..062ff86 100644 --- a/src/sshare/plugins/default/current_time.py +++ b/src/sshare/plugins/default/current_time.py @@ -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):