summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-10-24 11:04:39 -0500
committerJohn Estabrook <jestabro@vyos.io>2024-10-24 11:04:39 -0500
commitbd64f4508d72d1b2f0c613b5012ad6dc9507f3c6 (patch)
treeb2c02c511b6b80b0995a9dd64adc77922d807461 /src
parent22478789c282dc379e7d7ce1c910a9a301f7b49b (diff)
downloadvyos1x-config-bd64f4508d72d1b2f0c613b5012ad6dc9507f3c6.tar.gz
vyos1x-config-bd64f4508d72d1b2f0c613b5012ad6dc9507f3c6.zip
T6718: add function refpath: config path -> reference_tree path
Diffstat (limited to 'src')
-rw-r--r--src/reference_tree.ml11
-rw-r--r--src/reference_tree.mli2
2 files changed, 13 insertions, 0 deletions
diff --git a/src/reference_tree.ml b/src/reference_tree.ml
index e920209..353a152 100644
--- a/src/reference_tree.ml
+++ b/src/reference_tree.ml
@@ -340,6 +340,17 @@ let get_completion_data reftree path =
(data.node_type, data.multi, data.help)
in List.map aux (Vytree.children_of_node @@ Vytree.get reftree path)
+(* Convert from config path to reference tree path *)
+let refpath reftree path =
+ let rec aux acc p =
+ match acc, p with
+ | [], h :: tl -> aux (acc @ [h]) tl
+ | _, [h] -> if is_tag reftree acc then acc else acc @ [h]
+ | _, h :: h' :: tl -> if is_tag reftree acc then aux (acc @ [h']) tl
+ else aux (acc @ [h]) ([h'] @ tl)
+ | _, [] -> acc
+ in aux [] path
+
module JSONRenderer =
struct
let render_data data =
diff --git a/src/reference_tree.mli b/src/reference_tree.mli
index 129e5db..964380e 100644
--- a/src/reference_tree.mli
+++ b/src/reference_tree.mli
@@ -62,4 +62,6 @@ val get_value_help : t -> string list -> (string * string) list
val get_completion_data : t -> string list -> (node_type * bool * string) list
+val refpath : t -> string list -> string list
+
val render_json : t -> string