From 653d78659a9f3cb6ea6942ae9879fc99b4c0c9d9 Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Tue, 20 Mar 2018 09:25:26 +0100 Subject: Updated help function to not use inline loop. Inlining the loop in help made the output quite large for no real gain in perfomance. --- clap.zig | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'clap.zig') diff --git a/clap.zig b/clap.zig index 0ce7469..410a65f 100644 --- a/clap.zig +++ b/clap.zig @@ -210,7 +210,7 @@ pub fn Parser(comptime Result: type, comptime ParseError: type, comptime default break :blk res; }; - inline for (options) |option| { + for (options) |option| { if (option.short == null and option.long == null) continue; try out_stream.print(" "); @@ -231,9 +231,11 @@ pub fn Parser(comptime Result: type, comptime ParseError: type, comptime default const missing_spaces = comptime blk: { var res = longest_long + 3; if (option.long) |long| { + try out_stream.print("--{}", long); res -= 2 + long.len; if (option.takes_value) { + try out_stream.print("{}", equal_value); res -= equal_value.len; } } @@ -241,15 +243,10 @@ pub fn Parser(comptime Result: type, comptime ParseError: type, comptime default break :blk res; }; - if (option.long) |long| { - try out_stream.print("--{}", long); - - if (option.takes_value) { - try out_stream.print("{}", equal_value); - } + var i = usize(0); + while (i < missing_spaces) : (i += 1) { + try out_stream.print(" "); } - - try out_stream.print(" " ** missing_spaces); try out_stream.print("{}\n", option.help); } } @@ -343,7 +340,7 @@ test "clap.parse.Example" { assert(res.g == case.res.g); assert(res.b == case.res.b); } else |err| { - assert(err == (case.err ?? unreachable)); + assert(err == ??case.err); } } } -- cgit v1.2.3