diff options
| author | 2018-03-20 09:25:26 +0100 | |
|---|---|---|
| committer | 2018-03-20 09:25:26 +0100 | |
| commit | 653d78659a9f3cb6ea6942ae9879fc99b4c0c9d9 (patch) | |
| tree | fadbde8aea5c67c01e8d76cbdc5d2139e1958464 | |
| parent | Fixed help fn (diff) | |
| download | zig-clap-653d78659a9f3cb6ea6942ae9879fc99b4c0c9d9.tar.gz zig-clap-653d78659a9f3cb6ea6942ae9879fc99b4c0c9d9.tar.xz zig-clap-653d78659a9f3cb6ea6942ae9879fc99b4c0c9d9.zip | |
Updated help function to not use inline loop.
Inlining the loop in help made the output quite large for no real gain
in perfomance.
| -rw-r--r-- | clap.zig | 17 |
1 files changed, 7 insertions, 10 deletions
| @@ -210,7 +210,7 @@ pub fn Parser(comptime Result: type, comptime ParseError: type, comptime default | |||
| 210 | break :blk res; | 210 | break :blk res; |
| 211 | }; | 211 | }; |
| 212 | 212 | ||
| 213 | inline for (options) |option| { | 213 | for (options) |option| { |
| 214 | if (option.short == null and option.long == null) continue; | 214 | if (option.short == null and option.long == null) continue; |
| 215 | 215 | ||
| 216 | try out_stream.print(" "); | 216 | try out_stream.print(" "); |
| @@ -231,9 +231,11 @@ pub fn Parser(comptime Result: type, comptime ParseError: type, comptime default | |||
| 231 | const missing_spaces = comptime blk: { | 231 | const missing_spaces = comptime blk: { |
| 232 | var res = longest_long + 3; | 232 | var res = longest_long + 3; |
| 233 | if (option.long) |long| { | 233 | if (option.long) |long| { |
| 234 | try out_stream.print("--{}", long); | ||
| 234 | res -= 2 + long.len; | 235 | res -= 2 + long.len; |
| 235 | 236 | ||
| 236 | if (option.takes_value) { | 237 | if (option.takes_value) { |
| 238 | try out_stream.print("{}", equal_value); | ||
| 237 | res -= equal_value.len; | 239 | res -= equal_value.len; |
| 238 | } | 240 | } |
| 239 | } | 241 | } |
| @@ -241,15 +243,10 @@ pub fn Parser(comptime Result: type, comptime ParseError: type, comptime default | |||
| 241 | break :blk res; | 243 | break :blk res; |
| 242 | }; | 244 | }; |
| 243 | 245 | ||
| 244 | if (option.long) |long| { | 246 | var i = usize(0); |
| 245 | try out_stream.print("--{}", long); | 247 | while (i < missing_spaces) : (i += 1) { |
| 246 | 248 | try out_stream.print(" "); | |
| 247 | if (option.takes_value) { | ||
| 248 | try out_stream.print("{}", equal_value); | ||
| 249 | } | ||
| 250 | } | 249 | } |
| 251 | |||
| 252 | try out_stream.print(" " ** missing_spaces); | ||
| 253 | try out_stream.print("{}\n", option.help); | 250 | try out_stream.print("{}\n", option.help); |
| 254 | } | 251 | } |
| 255 | } | 252 | } |
| @@ -343,7 +340,7 @@ test "clap.parse.Example" { | |||
| 343 | assert(res.g == case.res.g); | 340 | assert(res.g == case.res.g); |
| 344 | assert(res.b == case.res.b); | 341 | assert(res.b == case.res.b); |
| 345 | } else |err| { | 342 | } else |err| { |
| 346 | assert(err == (case.err ?? unreachable)); | 343 | assert(err == ??case.err); |
| 347 | } | 344 | } |
| 348 | } | 345 | } |
| 349 | } | 346 | } |