pretty_print.d
· 621 B · D
Raw
private void print_help(const ref GetoptResult help_info)
{
import core.runtime;
import std.path : baseName;
import std.algorithm : map, maxElement;
writefln("Usage: %s [OPTION...]", Runtime.args[0].baseName);
writeln();
writeln("Program description");
writeln();
writeln("Options:");
string[] flags;
foreach (opt; help_info.options)
flags ~= opt.optShort ~ (opt.optShort.length ? ", " : " ") ~ opt.optLong;
size_t width = flags.map!(f => f.length).maxElement + 1;
foreach (i, opt; help_info.options)
writefln(" %-*s %s", width, flags[i], opt.help);
}
| 1 | private void print_help(const ref GetoptResult help_info) |
| 2 | { |
| 3 | import core.runtime; |
| 4 | import std.path : baseName; |
| 5 | import std.algorithm : map, maxElement; |
| 6 | |
| 7 | writefln("Usage: %s [OPTION...]", Runtime.args[0].baseName); |
| 8 | writeln(); |
| 9 | writeln("Program description"); |
| 10 | writeln(); |
| 11 | writeln("Options:"); |
| 12 | |
| 13 | string[] flags; |
| 14 | foreach (opt; help_info.options) |
| 15 | flags ~= opt.optShort ~ (opt.optShort.length ? ", " : " ") ~ opt.optLong; |
| 16 | |
| 17 | size_t width = flags.map!(f => f.length).maxElement + 1; |
| 18 | |
| 19 | foreach (i, opt; help_info.options) |
| 20 | writefln(" %-*s %s", width, flags[i], opt.help); |
| 21 | } |