Added --config flag

This commit is contained in:
Gnarwhal 2024-09-08 20:28:33 +00:00
parent 10b5a80a09
commit 6a310b8ca9
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174

View file

@ -28,20 +28,26 @@ from sshare.version import version
def main():
# TODO: Add --config flag
arg_parser = argparse.ArgumentParser(
prog="sshare",
description="Upload files to a server via ssh",
add_help=False,
)
arg_parser.add_argument(
"--config",
metavar="config",
help="Specify location of config file to use"
)
arguments, _ = arg_parser.parse_known_args()
config_directory = Path(os.environ.get("XDG_CONFIG_DIR", f"{os.environ["HOME"]}/.config")) / "sshare"
with open(config_directory / "config.toml", mode="rb") as file:
with open(arguments.config or (config_directory / "config.toml"), mode="rb") as file:
config = tomllib.load(file)
INTERNAL_PLUGIN_LOCATION = "sshare.plugins.default"
# Load command line early and set it as the active logger
# so that it can be used to report errors while loading and
# configuring other loggers
command_line = Plugin.internal(INTERNAL_PLUGIN_LOCATION, "command_line", config.get("plugins", dict()))
logger = Logger(command_line=command_line)
arg_parser = argparse.ArgumentParser(
prog = "sshare",
description = "Upload files to a server via ssh",
arg_parser.add_argument(
"-h",
"--help",
action="help",
help="show this help message and exit"
)
arg_parser.add_argument(
"-v",
@ -49,6 +55,13 @@ def main():
action="version",
version=f"%(prog)s version {version}",
)
INTERNAL_PLUGIN_LOCATION = "sshare.plugins.default"
# Load command line early and set it as the active logger
# so that it can be used to report errors while loading and
# configuring other loggers
command_line = Plugin.internal(INTERNAL_PLUGIN_LOCATION, "command_line", config.get("plugins", dict()))
logger = Logger(command_line=command_line)
plugins = PluginManager(
[ "logger", "source", "name", "upload", "result" ],
logger,