diff options
author | Daniil Baturin <daniil@baturin.org> | 2018-02-17 23:15:57 +0700 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2018-02-17 23:15:57 +0700 |
commit | bfa93363f3e8533ef352cad38c2adfa21dbc28a3 (patch) | |
tree | 4c5786f9688f018d5cbead2588c409802d9dbc31 /src/config_tree.ml | |
parent | d4ee9b96e02e1413cc19ce638aec07408468ca30 (diff) | |
download | vyconf-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/config_tree.ml')
-rw-r--r-- | src/config_tree.ml | 19 |
1 files changed, 18 insertions, 1 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 |