summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2018-02-17 23:15:57 +0700
committerDaniil Baturin <daniil@baturin.org>2018-02-17 23:15:57 +0700
commitbfa93363f3e8533ef352cad38c2adfa21dbc28a3 (patch)
tree4c5786f9688f018d5cbead2588c409802d9dbc31 /src
parentd4ee9b96e02e1413cc19ce638aec07408468ca30 (diff)
downloadvyconf-bfa93363f3e8533ef352cad38c2adfa21dbc28a3.tar.gz
vyconf-bfa93363f3e8533ef352cad38c2adfa21dbc28a3.zip
Add Config_tree.render_at_level function for correct rendering of configs for human consumption.
The idea of the correct (for subsequent parsing) and familiar for all other purposes rendering: * When rendering the entire config, do not render the invisible "root" node, only render its children. * When rendering config at specified path, do not include any nodes that are within the path (e.g. if path "system login" exists, "show system" request output should start with "login {", not "system { login { ...").
Diffstat (limited to 'src')
-rw-r--r--src/config_tree.ml19
-rw-r--r--src/config_tree.mli12
2 files changed, 29 insertions, 2 deletions
diff --git a/src/config_tree.ml b/src/config_tree.ml
index 9fed465..c816d65 100644
--- a/src/config_tree.ml
+++ b/src/config_tree.ml
@@ -156,7 +156,7 @@ struct
let render
?(indent=4)
- ?(reftree)
+ ?(reftree=None)
?(cmp=BatString.numeric_compare)
?(showephemeral=false)
?(showinactive=false)
@@ -249,3 +249,20 @@ struct
end (* Renderer *)
let render = Renderer.render
+
+let render_at_level
+ ?(indent=4)
+ ?(reftree=None)
+ ?(cmp=BatString.numeric_compare)
+ ?(showephemeral=false)
+ ?(showinactive=false)
+ node
+ path =
+ let node =
+ match path with
+ | [] -> node
+ | _ -> Vytree.get node path
+ in
+ let children = Vytree.children_of_node node in
+ let child_configs = List.map (render ~indent:indent ~reftree:reftree ~cmp:cmp ~showephemeral:showephemeral ~showinactive:showinactive) children in
+ List.fold_left (Printf.sprintf "%s\n%s") "" child_configs
diff --git a/src/config_tree.mli b/src/config_tree.mli
index f724df1..f72eda9 100644
--- a/src/config_tree.mli
+++ b/src/config_tree.mli
@@ -56,10 +56,20 @@ val is_ephemeral : t -> string list -> bool
*)
val render :
?indent:int ->
- ?reftree:Reference_tree.t ->
+ ?reftree:(Reference_tree.t option)->
?cmp:(string -> string -> int) ->
?showephemeral:bool ->
?showinactive:bool ->
t ->
string
+val render_at_level :
+ ?indent:int ->
+ ?reftree:(Reference_tree.t option)->
+ ?cmp:(string -> string -> int) ->
+ ?showephemeral:bool ->
+ ?showinactive:bool ->
+ t ->
+ string list ->
+ string
+