Added --config flag
This commit is contained in:
parent
10b5a80a09
commit
6a310b8ca9
1 changed files with 24 additions and 11 deletions
|
@ -28,20 +28,26 @@ from sshare.version import version
|
||||||
|
|
||||||
|
|
||||||
def main():
|
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"
|
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)
|
config = tomllib.load(file)
|
||||||
|
|
||||||
INTERNAL_PLUGIN_LOCATION = "sshare.plugins.default"
|
arg_parser.add_argument(
|
||||||
# Load command line early and set it as the active logger
|
"-h",
|
||||||
# so that it can be used to report errors while loading and
|
"--help",
|
||||||
# configuring other loggers
|
action="help",
|
||||||
command_line = Plugin.internal(INTERNAL_PLUGIN_LOCATION, "command_line", config.get("plugins", dict()))
|
help="show this help message and exit"
|
||||||
logger = Logger(command_line=command_line)
|
|
||||||
arg_parser = argparse.ArgumentParser(
|
|
||||||
prog = "sshare",
|
|
||||||
description = "Upload files to a server via ssh",
|
|
||||||
)
|
)
|
||||||
arg_parser.add_argument(
|
arg_parser.add_argument(
|
||||||
"-v",
|
"-v",
|
||||||
|
@ -49,6 +55,13 @@ def main():
|
||||||
action="version",
|
action="version",
|
||||||
version=f"%(prog)s version {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(
|
plugins = PluginManager(
|
||||||
[ "logger", "source", "name", "upload", "result" ],
|
[ "logger", "source", "name", "upload", "result" ],
|
||||||
logger,
|
logger,
|
||||||
|
|
Loading…
Reference in a new issue