summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clap.zig17
1 files changed, 7 insertions, 10 deletions
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
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}