diff options
| author | Daniel Weipert <git@mail.dweipert.de> | 2026-03-14 23:13:04 +0100 |
|---|---|---|
| committer | Daniel Weipert <git@mail.dweipert.de> | 2026-03-14 23:13:04 +0100 |
| commit | 91e1d070b2ee8096ccc3c8c4dbc5a927ed1e8942 (patch) | |
| tree | 50cfcda74e14d34dce472ff2658092782cc5e855 | |
| parent | 3f67eb415e5458d50711d55f136f86b2ac6b7ff0 (diff) | |
add comands to add config keys to remote config
| -rwxr-xr-x | rclone-ide | 61 |
1 files changed, 57 insertions, 4 deletions
@@ -91,6 +91,9 @@ def build_cmd_local_path(config: Mapping[str, Any]) -> str: global config_dir + if "rclone_ide_local_path" not in config: + raise KeyError("rclone_ide_local_path is not specified") + if config["rclone_ide_local_path"] in [".", "./"]: return config_dir @@ -102,6 +105,9 @@ def build_cmd_local_path(config: Mapping[str, Any]) -> str: def build_cmd_remote_path(remote: str, config: Mapping[str, Any]) -> str: """Build the remote path part for the rclone command""" + if "rclone_ide_remote_path" not in config: + raise KeyError("rclone_ide_remote_path is not specified") + return "{}:{}".format(remote, config["rclone_ide_remote_path"]) @@ -135,6 +141,38 @@ def build_cmd_logging(log_level: str = "INFO") -> List[str]: return cmd +def command_set_local_path(options: Mapping[str, Any]) -> None: + """Set the config option for the given remote for the local path""" + + cmd = [ + "rclone", "config", "update", + options.remote, + "rclone_ide_local_path", options.local_path, + build_cmd_config(), + ] + + if options.dry_run: + print(" ".join(cmd)) + else: + subprocess.run(cmd) + + +def command_set_remote_path(options: Mapping[str, Any]) -> None: + """Set the config option for the given remote for the remote path""" + + cmd = [ + "rclone", "config", "update", + options.remote, + "rclone_ide_remote_path", options.remote_path, + build_cmd_config(), + ] + + if options.dry_run: + print(" ".join(cmd)) + else: + subprocess.run(cmd) + + def command_copy_file(options: Mapping[str, Any]) -> None: """Copy specific file to remote""" @@ -160,7 +198,7 @@ def command_copy_file(options: Mapping[str, Any]) -> None: ] if options.dry_run: - print(cmd) + print(" ".join(cmd)) else: subprocess.run(cmd) @@ -172,10 +210,20 @@ parser = argparse.ArgumentParser( subparsers = parser.add_subparsers(dest="command") -parser.add_argument("--dry-run", action="store_true") +parser.add_argument("--dry-run", action="store_true") # TODO: add to all subparsers? + + +parser_set_local_path = subparsers.add_parser("set-local-path") +parser_set_local_path.add_argument("remote", choices=config.keys()) +parser_set_local_path.add_argument("local_path") + + +parser_set_remote_path = subparsers.add_parser("set-remote-path") +parser_set_remote_path.add_argument("remote", choices=config.keys()) +parser_set_remote_path.add_argument("remote_path") -parser_copy_file = subparsers.add_parser("copyFile") +parser_copy_file = subparsers.add_parser("copy-file") parser_copy_file.add_argument("remote", help="rclone remote to upload to", choices=config.keys()) parser_copy_file.add_argument("filepath", help="cwd-relative path to file") @@ -185,7 +233,12 @@ args = parser.parse_args() if args.command: match args.command: - case "copyFile": + case "set-local-path": + command_set_local_path(args) + case "set-remote-path": + command_set_remote_path(args) + + case "copy-file": command_copy_file(args) else: |
