diff options
| author | John Estabrook <jestabro@vyos.io> | 2026-02-24 21:56:22 -0600 |
|---|---|---|
| committer | John Estabrook <jestabro@vyos.io> | 2026-03-04 15:44:38 +0100 |
| commit | 3147fb1498070eccc733e3e3ff70281e5d8a8064 (patch) | |
| tree | 6e7ab4f1a6f8ea98f16503a07a34f138f295e193 /src | |
| parent | 6502d8b21e0dd7fb5efe012742dd46d3547cdfff (diff) | |
| download | vyconf-3147fb1498070eccc733e3e3ff70281e5d8a8064.tar.gz vyconf-3147fb1498070eccc733e3e3ff70281e5d8a8064.zip | |
T8313: add copy/rename client methods
Diffstat (limited to 'src')
| -rw-r--r-- | src/vyconf_cli.ml | 8 | ||||
| -rw-r--r-- | src/vyconf_client.ml | 22 | ||||
| -rw-r--r-- | src/vyconf_client.mli | 4 |
3 files changed, 34 insertions, 0 deletions
diff --git a/src/vyconf_cli.ml b/src/vyconf_cli.ml index 8563572..67aaa7a 100644 --- a/src/vyconf_cli.ml +++ b/src/vyconf_cli.ml @@ -5,12 +5,16 @@ type op_t = | OpSet | OpDelete | OpDiscard + | OpCopy + | OpRename let op_of_string s = match s with | "vy_set" -> OpSet | "vy_delete" -> OpDelete | "vy_discard" -> OpDiscard + | "vy_copy" -> OpCopy + | "vy_rename" -> OpRename | _ -> failwith (Printf.sprintf "Unknown operation %s" s) let config_format_of_string s = @@ -76,6 +80,8 @@ let main op path = | OpSet -> set c path | OpDelete -> delete c path | OpDiscard -> discard c + | OpCopy -> copy c path + | OpRename -> rename c path end | Error e -> Error e |> Lwt.return in @@ -109,5 +115,7 @@ let () = match op, path_list with | OpSet, [] | OpDelete, [] -> let () = print_endline "Must specify config path" in exit 1 + | OpCopy, [] | OpRename, [] -> + let () = print_endline "Copy and rename operations require configuration paths" in exit 1 | _, _ -> let result = Lwt_main.run (main op path_list) in exit result diff --git a/src/vyconf_client.ml b/src/vyconf_client.ml index 6b6c6f1..d866ad4 100644 --- a/src/vyconf_client.ml +++ b/src/vyconf_client.ml @@ -254,3 +254,25 @@ let get_completion_env client path = (* legacy getCompletionEnv is silent on error *) | Fail -> Error "" |> Lwt.return | _ -> Error (Option.value resp.error ~default:"") |> Lwt.return + +let copy client path = + let path_arr = Array.of_list path in + let path1 = Array.to_list (Array.sub path_arr 0 2) in + let path2 = Array.to_list (Array.sub path_arr 3 2) in + let req = Copy {source=path1; destination=path2;} in + let%lwt resp = do_request client req in + match resp.status with + | Success -> Lwt.return (Ok "") + | Fail -> Error (Option.value resp.error ~default:"") |> Lwt.return + | _ -> Error (Option.value resp.error ~default:"") |> Lwt.return + +let rename client path = + let path_arr = Array.of_list path in + let path1 = Array.to_list (Array.sub path_arr 0 2) in + let path2 = Array.to_list (Array.sub path_arr 3 2) in + let req = Rename {source=path1; destination=path2;} in + let%lwt resp = do_request client req in + match resp.status with + | Success -> Lwt.return (Ok "") + | Fail -> Error (Option.value resp.error ~default:"") |> Lwt.return + | _ -> Error (Option.value resp.error ~default:"") |> Lwt.return diff --git a/src/vyconf_client.mli b/src/vyconf_client.mli index 3ee1083..9c5a453 100644 --- a/src/vyconf_client.mli +++ b/src/vyconf_client.mli @@ -55,3 +55,7 @@ val reference_path_exists : t -> string list -> (string, string) result Lwt.t val get_path_type : t -> string list -> (string, string) result Lwt.t val get_completion_env : t -> string list -> (string, string) result Lwt.t + +val copy : t -> string list -> (string, string) result Lwt.t + +val rename : t -> string list -> (string, string) result Lwt.t |
