summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Komari Spaghetti2021-09-05 22:30:16 +0200
committerGravatar Komari Spaghetti2021-09-05 22:30:16 +0200
commiteb81a66265a85e569e5aeeefefd2699b0eb1fe6e (patch)
tree613fce9109cad0d6542d52ac69d3042e56cc98bd
parentUpdate calls to tokenizer (diff)
parentIndent help text on every new line to allow for user-controlled wrapping (diff)
downloadzig-clap-eb81a66265a85e569e5aeeefefd2699b0eb1fe6e.tar.gz
zig-clap-eb81a66265a85e569e5aeeefefd2699b0eb1fe6e.tar.xz
zig-clap-eb81a66265a85e569e5aeeefefd2699b0eb1fe6e.zip
Merge branch 'master' into zig-master
-rw-r--r--clap.zig15
-rw-r--r--example/simple-ex.zig8
-rw-r--r--example/simple.zig8
-rw-r--r--example/streaming-clap.zig6
4 files changed, 25 insertions, 12 deletions
diff --git a/clap.zig b/clap.zig
index 0bc711b..e108c9b 100644
--- a/clap.zig
+++ b/clap.zig
@@ -408,7 +408,16 @@ pub fn helpFull(
408 try stream.print("\t", .{}); 408 try stream.print("\t", .{});
409 try printParam(cs.writer(), Id, param, Error, context, valueText); 409 try printParam(cs.writer(), Id, param, Error, context, valueText);
410 try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, cs.bytes_written)); 410 try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, cs.bytes_written));
411 try stream.print("\t{s}\n", .{try helpText(context, param)}); 411 const help_text = try helpText(context, param);
412 var help_text_line_it = mem.split(help_text, "\n");
413 var indent_line = false;
414 while (help_text_line_it.next()) |line| : (indent_line = true) {
415 if (indent_line) {
416 try stream.print("\t", .{});
417 try stream.writeByteNTimes(' ', max_spacing);
418 }
419 try stream.print("\t{s}\n", .{line});
420 }
412 } 421 }
413} 422}
414 423
@@ -509,6 +518,7 @@ test "clap.help" {
509 parseParam("--aa Long flag.") catch unreachable, 518 parseParam("--aa Long flag.") catch unreachable,
510 parseParam("--bb <V2> Long option.") catch unreachable, 519 parseParam("--bb <V2> Long option.") catch unreachable,
511 parseParam("-c, --cc Both flag.") catch unreachable, 520 parseParam("-c, --cc Both flag.") catch unreachable,
521 parseParam("--complicate Flag with a complicated and\nvery long description that\nspans multiple lines.") catch unreachable,
512 parseParam("-d, --dd <V3> Both option.") catch unreachable, 522 parseParam("-d, --dd <V3> Both option.") catch unreachable,
513 parseParam("-d, --dd <V3>... Both repeated option.") catch unreachable, 523 parseParam("-d, --dd <V3>... Both repeated option.") catch unreachable,
514 parseParam( 524 parseParam(
@@ -523,6 +533,9 @@ test "clap.help" {
523 "\t --aa \tLong flag.\n" ++ 533 "\t --aa \tLong flag.\n" ++
524 "\t --bb <V2> \tLong option.\n" ++ 534 "\t --bb <V2> \tLong option.\n" ++
525 "\t-c, --cc \tBoth flag.\n" ++ 535 "\t-c, --cc \tBoth flag.\n" ++
536 "\t --complicate\tFlag with a complicated and\n" ++
537 "\t \tvery long description that\n" ++
538 "\t \tspans multiple lines.\n" ++
526 "\t-d, --dd <V3> \tBoth option.\n" ++ 539 "\t-d, --dd <V3> \tBoth option.\n" ++
527 "\t-d, --dd <V3>...\tBoth repeated option.\n"; 540 "\t-d, --dd <V3>...\tBoth repeated option.\n";
528 541
diff --git a/example/simple-ex.zig b/example/simple-ex.zig
index 838b9c2..5653fd1 100644
--- a/example/simple-ex.zig
+++ b/example/simple-ex.zig
@@ -36,11 +36,11 @@ pub fn main() !void {
36 defer args.deinit(); 36 defer args.deinit();
37 37
38 if (args.flag("--help")) 38 if (args.flag("--help"))
39 debug.warn("--help\n", .{}); 39 debug.print("--help\n", .{});
40 if (args.option("--number")) |n| 40 if (args.option("--number")) |n|
41 debug.warn("--number = {s}\n", .{n}); 41 debug.print("--number = {s}\n", .{n});
42 for (args.options("--string")) |s| 42 for (args.options("--string")) |s|
43 debug.warn("--string = {s}\n", .{s}); 43 debug.print("--string = {s}\n", .{s});
44 for (args.positionals()) |pos| 44 for (args.positionals()) |pos|
45 debug.warn("{s}\n", .{pos}); 45 debug.print("{s}\n", .{pos});
46} 46}
diff --git a/example/simple.zig b/example/simple.zig
index 78a963c..ff6d301 100644
--- a/example/simple.zig
+++ b/example/simple.zig
@@ -26,11 +26,11 @@ pub fn main() !void {
26 defer args.deinit(); 26 defer args.deinit();
27 27
28 if (args.flag("--help")) 28 if (args.flag("--help"))
29 debug.warn("--help\n", .{}); 29 debug.print("--help\n", .{});
30 if (args.option("--number")) |n| 30 if (args.option("--number")) |n|
31 debug.warn("--number = {s}\n", .{n}); 31 debug.print("--number = {s}\n", .{n});
32 for (args.options("--string")) |s| 32 for (args.options("--string")) |s|
33 debug.warn("--string = {s}\n", .{s}); 33 debug.print("--string = {s}\n", .{s});
34 for (args.positionals()) |pos| 34 for (args.positionals()) |pos|
35 debug.warn("{s}\n", .{pos}); 35 debug.print("{s}\n", .{pos});
36} 36}
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig
index 5f7f219..9ed38dd 100644
--- a/example/streaming-clap.zig
+++ b/example/streaming-clap.zig
@@ -44,13 +44,13 @@ pub fn main() !void {
44 }) |arg| { 44 }) |arg| {
45 // arg.param will point to the parameter which matched the argument. 45 // arg.param will point to the parameter which matched the argument.
46 switch (arg.param.id) { 46 switch (arg.param.id) {
47 'h' => debug.warn("Help!\n", .{}), 47 'h' => debug.print("Help!\n", .{}),
48 'n' => debug.warn("--number = {s}\n", .{arg.value.?}), 48 'n' => debug.print("--number = {s}\n", .{arg.value.?}),
49 49
50 // arg.value == null, if arg.param.takes_value == .none. 50 // arg.value == null, if arg.param.takes_value == .none.
51 // Otherwise, arg.value is the value passed with the argument, such as "-a=10" 51 // Otherwise, arg.value is the value passed with the argument, such as "-a=10"
52 // or "-a 10". 52 // or "-a 10".
53 'f' => debug.warn("{s}\n", .{arg.value.?}), 53 'f' => debug.print("{s}\n", .{arg.value.?}),
54 else => unreachable, 54 else => unreachable,
55 } 55 }
56 } 56 }