@@ -2,7 +2,7 @@ module commandr.help;
22
33import commandr.program;
44import commandr.option;
5- import std.algorithm : filter, map, any, chunkBy;
5+ import std.algorithm : filter, map, any, chunkBy, sort ;
66import std.array : join, array;
77import std.conv : to;
88import std.stdio : writefln, writeln, write;
@@ -160,7 +160,19 @@ struct HelpPrinter {
160160 }
161161
162162 private void printSubcommands (Command[string ] commands) {
163- auto grouped = commands.values .chunkBy! (a => a.topic).array;
163+ auto grouped = commands.values
164+ .sort! ((a, b) {
165+ // Note, when we used chunkBy, it is expected that range
166+ // is already sorted by the key, thus before grouping,
167+ // we have to sort by topic first.
168+ // And then by name for better output
169+ // (because associative array do not preserver order).
170+ if (a.topic == b.topic)
171+ return a.name < b.name;
172+ return a.topic < b.topic;
173+ })
174+ .chunkBy! (a => a.topic)
175+ .array;
164176
165177 if (grouped.length == 1 && grouped[0 ][0 ] is null ) {
166178 foreach (key, command; commands) {
0 commit comments