From 954c63727874b33fc221197b60042439330d13bd Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Wed, 5 Nov 2025 14:28:27 -0600 Subject: T7988: return difference of running and proposed config for show_config Request show_config returns the format familiar from legacy behavior: a replacement for the config-mode 'show' command. --- src/session.ml | 36 +++++++++++------------------------- src/session.mli | 2 +- src/vyconfd.ml | 3 +-- 3 files changed, 13 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/session.ml b/src/session.ml index 46f1b36..03c5f91 100644 --- a/src/session.ml +++ b/src/session.ml @@ -499,29 +499,15 @@ let exists w s path = else let c = get_proposed_config w s in (VT.exists[@alert "-exn"]) c path -let show_config w s path fmt = - (* alert exn VT.exists: - [Vytree.Empty_path] non-empty in conditional - alert exn CT.render_at_level: - [Vytree.Nonexistent_path] checked by VT.exists - alert exn VT.get: - [Vytree.Empty_path] non-empty in pattern match - [Vytree.Nonexistent_path] checked by VT.exists - *) - let open Vyconf_connect.Vyconf_pbt in - let c = get_proposed_config w s in - if (path <> []) && not ((VT.exists[@alert "-exn"]) c path) then - raise (Session_error ("Path does not exist")) +let show_config w s path = + let proposed_config = get_proposed_config w s in + if (path <> []) && not ((VT.exists[@alert "-exn"]) proposed_config path) + then raise (Session_error "Path does not exist") else - let node = c in - match fmt with - | Curly -> (CT.render_at_level[@alert "-exn"]) node path - | Json -> - let node = - begin - match path with - | [] -> c - | _ as ps -> (VT.get[@alert "-exn"]) c ps - end - in - CT.to_yojson node |> Yojson.Safe.pretty_to_string + let res = + (CD.diff_show[@alert "-exn"]) + w.reference_tree + path + w.running_config + proposed_config + in res diff --git a/src/session.mli b/src/session.mli index f8327db..cb3f37a 100644 --- a/src/session.mli +++ b/src/session.mli @@ -80,4 +80,4 @@ val get_config : world -> session_data -> string -> string val cleanup_config : world -> string -> unit -val show_config : world -> session_data -> string list -> Vyconf_connect.Vyconf_pbt.request_config_format -> string +val show_config : world -> session_data -> string list -> string diff --git a/src/vyconfd.ml b/src/vyconfd.ml index dee5535..c09c4f4 100644 --- a/src/vyconfd.ml +++ b/src/vyconfd.ml @@ -183,8 +183,7 @@ let list_children world token (req: request_list_children) = let show_config world token (req: request_show_config) = try - let fmt = Option.value req.format ~default:Curly in - let conf_str = Session.show_config world (find_session token) req.path fmt in + let conf_str = Session.show_config world (find_session token) req.path in {response_tmpl with output=(Some conf_str)} with Session.Session_error msg -> {response_tmpl with status=Fail; error=(Some msg)} -- cgit v1.2.3