diff --git a/src/sshare/main.py b/src/sshare/main.py index 9999af6..3a71c08 100644 --- a/src/sshare/main.py +++ b/src/sshare/main.py @@ -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,