diff options
-rw-r--r-- | src/config_tree.ml | 7 | ||||
-rw-r--r-- | src/config_tree.mli | 2 | ||||
-rw-r--r-- | src/vytree.ml | 5 | ||||
-rw-r--r-- | src/vytree.mli | 2 |
4 files changed, 13 insertions, 3 deletions
diff --git a/src/config_tree.ml b/src/config_tree.ml index c6fddb4..9b630d9 100644 --- a/src/config_tree.ml +++ b/src/config_tree.ml @@ -331,12 +331,15 @@ let render_at_level 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 -let render_commands ?(reftree=None) ?(alwayssort=false) node path = +let render_commands ?(reftree=None) ?(alwayssort=false) ?(sortchildren=false) node path = let node = match path with | [] -> node | _ -> Vytree.get node path in - let children = Vytree.children_of_node node in + let children = + if sortchildren then Vytree.sorted_children_of_node (BatString.numeric_compare) node + else Vytree.children_of_node node + in let commands = List.map (Renderer.render_commands ~reftree:reftree ~alwayssort:alwayssort path) children in String.concat "\n" commands diff --git a/src/config_tree.mli b/src/config_tree.mli index 0e21f59..79426e3 100644 --- a/src/config_tree.mli +++ b/src/config_tree.mli @@ -75,4 +75,4 @@ val render_at_level : string list -> string -val render_commands: ?reftree:(Reference_tree.t option) -> ?alwayssort:bool -> t -> string list -> string +val render_commands: ?reftree:(Reference_tree.t option) -> ?alwayssort:bool -> ?sortchildren:bool -> t -> string list -> string diff --git a/src/vytree.ml b/src/vytree.ml index 156b326..b200cc4 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -164,3 +164,8 @@ let get_existent_path node path = let children_of_path node path = let node' = get node path in list_children node' + +let sorted_children_of_node cmp node = + let names = list_children node in + let names = List.sort cmp names in + List.map (find_or_fail node) names diff --git a/src/vytree.mli b/src/vytree.mli index 9bc8844..da593f1 100644 --- a/src/vytree.mli +++ b/src/vytree.mli @@ -40,3 +40,5 @@ val get_data : 'a t -> string list -> 'a val exists : 'a t -> string list -> bool val children_of_path : 'a t -> string list -> string list + +val sorted_children_of_node : (string -> string -> int) -> 'a t -> ('a t) list |