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..023480a 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"], @@ -78,6 +79,7 @@ def main(): plugins.add_from( Plugin.internal(INTERNAL_PLUGIN_LOCATION), "file", + "stdin", "current_time", "append_type", "ssh", @@ -99,6 +101,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/config.py b/src/sshare/plugins/config.py index 31c18d8..6df34ed 100644 --- a/src/sshare/plugins/config.py +++ b/src/sshare/plugins/config.py @@ -75,8 +75,8 @@ class Argument: def add(self, arg_parser): flags = [] - if self._short: flags.append(f"-{self._short}") - if self._long: flags.append(f"--{self._long}") + if self._short != None: flags.append(f"-{self._short}") + if self._long != None: flags.append(f"--{self._long}") kwargs = self._kwargs | { "dest": self.dest() } 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): diff --git a/src/sshare/plugins/default/stdin.py b/src/sshare/plugins/default/stdin.py new file mode 100644 index 0000000..df359e4 --- /dev/null +++ b/src/sshare/plugins/default/stdin.py @@ -0,0 +1,31 @@ +# This file is part of SSHare. +# +# SSHare is free software: you can redistribute it and/or modify it under the terms of +# the GNU General Public License as published by the Free Software Foundation, +# either version 3 of the License, or (at your option) any later version. +# +# SSHare is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# SSHare. If not, see . + +import sys + +from sshare.plugins.config import Flag +from sshare.plugins.source import Raw + +plugin_type = "source" + +activate = { "stdin" } +config = { + "suffix": "txt" +} +args = { + "stdin": Flag(help="Upload from stdin") +} + +def get_source(): + return Raw(config.suffix, sys.stdin.buffer.read())