From 9bff7f332b86a18ff2f34e5c59ebdad5336e9850 Mon Sep 17 00:00:00 2001 From: Komari Spaghetti Date: Sat, 17 Jul 2021 10:43:05 +0000 Subject: Use debug.print instead of deprecated debug.warn in examples fixes comment on #11 --- example/simple-ex.zig | 8 ++++---- example/simple.zig | 8 ++++---- example/streaming-clap.zig | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) 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 { defer args.deinit(); if (args.flag("--help")) - debug.warn("--help\n", .{}); + debug.print("--help\n", .{}); if (args.option("--number")) |n| - debug.warn("--number = {s}\n", .{n}); + debug.print("--number = {s}\n", .{n}); for (args.options("--string")) |s| - debug.warn("--string = {s}\n", .{s}); + debug.print("--string = {s}\n", .{s}); for (args.positionals()) |pos| - debug.warn("{s}\n", .{pos}); + debug.print("{s}\n", .{pos}); } 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 { defer args.deinit(); if (args.flag("--help")) - debug.warn("--help\n", .{}); + debug.print("--help\n", .{}); if (args.option("--number")) |n| - debug.warn("--number = {s}\n", .{n}); + debug.print("--number = {s}\n", .{n}); for (args.options("--string")) |s| - debug.warn("--string = {s}\n", .{s}); + debug.print("--string = {s}\n", .{s}); for (args.positionals()) |pos| - debug.warn("{s}\n", .{pos}); + debug.print("{s}\n", .{pos}); } 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 { }) |arg| { // arg.param will point to the parameter which matched the argument. switch (arg.param.id) { - 'h' => debug.warn("Help!\n", .{}), - 'n' => debug.warn("--number = {s}\n", .{arg.value.?}), + 'h' => debug.print("Help!\n", .{}), + 'n' => debug.print("--number = {s}\n", .{arg.value.?}), // arg.value == null, if arg.param.takes_value == .none. // Otherwise, arg.value is the value passed with the argument, such as "-a=10" // or "-a 10". - 'f' => debug.warn("{s}\n", .{arg.value.?}), + 'f' => debug.print("{s}\n", .{arg.value.?}), else => unreachable, } } -- cgit v1.2.3 From 4be3fcdb616647215dc162c9e2f64b7d6e3ad09d Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Sun, 5 Sep 2021 13:14:17 -0700 Subject: Indent help text on every new line to allow for user-controlled wrapping --- clap.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/clap.zig b/clap.zig index 5bb3542..b280f70 100644 --- a/clap.zig +++ b/clap.zig @@ -408,7 +408,16 @@ pub fn helpFull( try stream.print("\t", .{}); try printParam(cs.writer(), Id, param, Error, context, valueText); try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, cs.bytes_written)); - try stream.print("\t{s}\n", .{try helpText(context, param)}); + const help_text = try helpText(context, param); + var help_text_line_it = mem.split(help_text, "\n"); + var indent_line = false; + while (help_text_line_it.next()) |line| : (indent_line = true) { + if (indent_line) { + try stream.print("\t", .{}); + try stream.writeByteNTimes(' ', max_spacing); + } + try stream.print("\t{s}\n", .{line}); + } } } @@ -509,6 +518,7 @@ test "clap.help" { parseParam("--aa Long flag.") catch unreachable, parseParam("--bb Long option.") catch unreachable, parseParam("-c, --cc Both flag.") catch unreachable, + parseParam("--complicate Flag with a complicated and\nvery long description that\nspans multiple lines.") catch unreachable, parseParam("-d, --dd Both option.") catch unreachable, parseParam("-d, --dd ... Both repeated option.") catch unreachable, parseParam( @@ -523,6 +533,9 @@ test "clap.help" { "\t --aa \tLong flag.\n" ++ "\t --bb \tLong option.\n" ++ "\t-c, --cc \tBoth flag.\n" ++ + "\t --complicate\tFlag with a complicated and\n" ++ + "\t \tvery long description that\n" ++ + "\t \tspans multiple lines.\n" ++ "\t-d, --dd \tBoth option.\n" ++ "\t-d, --dd ...\tBoth repeated option.\n"; -- cgit v1.2.3