diff options
Diffstat (limited to '')
| -rw-r--r-- | README.md | 18 | ||||
| -rw-r--r-- | build.zig | 5 | ||||
| -rw-r--r-- | clap.zig | 32 | ||||
| -rw-r--r-- | example/comptime-clap.zig | 6 | ||||
| -rw-r--r-- | example/simple.zig | 6 | ||||
| -rw-r--r-- | example/streaming-clap.zig | 6 |
6 files changed, 36 insertions, 37 deletions
| @@ -40,11 +40,11 @@ pub fn main() !void { | |||
| 40 | defer args.deinit(); | 40 | defer args.deinit(); |
| 41 | 41 | ||
| 42 | if (args.flag("--help")) | 42 | if (args.flag("--help")) |
| 43 | debug.warn("--help\n"); | 43 | debug.warn("--help\n", .{}); |
| 44 | if (args.option("--number")) |n| | 44 | if (args.option("--number")) |n| |
| 45 | debug.warn("--number = {}\n", n); | 45 | debug.warn("--number = {}\n", .{ n }); |
| 46 | for (args.positionals()) |pos| | 46 | for (args.positionals()) |pos| |
| 47 | debug.warn("{}\n", pos); | 47 | debug.warn("{}\n", .{ pos }); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | ``` | 50 | ``` |
| @@ -119,11 +119,11 @@ pub fn main() !void { | |||
| 119 | defer args.deinit(); | 119 | defer args.deinit(); |
| 120 | 120 | ||
| 121 | if (args.flag("--help")) | 121 | if (args.flag("--help")) |
| 122 | debug.warn("--help\n"); | 122 | debug.warn("--help\n", .{}); |
| 123 | if (args.option("--number")) |n| | 123 | if (args.option("--number")) |n| |
| 124 | debug.warn("--number = {}\n", n); | 124 | debug.warn("--number = {}\n", .{ n }); |
| 125 | for (args.positionals()) |pos| | 125 | for (args.positionals()) |pos| |
| 126 | debug.warn("{}\n", pos); | 126 | debug.warn("{}\n", .{ pos }); |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | ``` | 129 | ``` |
| @@ -174,13 +174,13 @@ pub fn main() !void { | |||
| 174 | while (try parser.next()) |arg| { | 174 | while (try parser.next()) |arg| { |
| 175 | // arg.param will point to the parameter which matched the argument. | 175 | // arg.param will point to the parameter which matched the argument. |
| 176 | switch (arg.param.id) { | 176 | switch (arg.param.id) { |
| 177 | 'h' => debug.warn("Help!\n"), | 177 | 'h' => debug.warn("Help!\n", .{}), |
| 178 | 'n' => debug.warn("--number = {}\n", arg.value.?), | 178 | 'n' => debug.warn("--number = {}\n", .{ arg.value.? }), |
| 179 | 179 | ||
| 180 | // arg.value == null, if arg.param.takes_value == false. | 180 | // arg.value == null, if arg.param.takes_value == false. |
| 181 | // Otherwise, arg.value is the value passed with the argument, such as "-a=10" | 181 | // Otherwise, arg.value is the value passed with the argument, such as "-a=10" |
| 182 | // or "-a 10". | 182 | // or "-a 10". |
| 183 | 'f' => debug.warn("{}\n", arg.value.?), | 183 | 'f' => debug.warn("{}\n", .{ arg.value.? }), |
| 184 | else => unreachable, | 184 | else => unreachable, |
| 185 | } | 185 | } |
| 186 | } | 186 | } |
| @@ -60,14 +60,13 @@ fn readMeStep(b: *Builder) *std.build.Step { | |||
| 60 | @setEvalBranchQuota(10000); | 60 | @setEvalBranchQuota(10000); |
| 61 | const file = try std.fs.File.openWrite("README.md"); | 61 | const file = try std.fs.File.openWrite("README.md"); |
| 62 | const stream = &file.outStream().stream; | 62 | const stream = &file.outStream().stream; |
| 63 | try stream.print( | 63 | try stream.print(@embedFile("example/README.md.template"), .{ |
| 64 | @embedFile("example/README.md.template"), | ||
| 65 | @embedFile("example/simple.zig"), | 64 | @embedFile("example/simple.zig"), |
| 66 | @embedFile("example/simple-error.zig"), | 65 | @embedFile("example/simple-error.zig"), |
| 67 | @embedFile("example/comptime-clap.zig"), | 66 | @embedFile("example/comptime-clap.zig"), |
| 68 | @embedFile("example/streaming-clap.zig"), | 67 | @embedFile("example/streaming-clap.zig"), |
| 69 | @embedFile("example/help.zig"), | 68 | @embedFile("example/help.zig"), |
| 70 | ); | 69 | }); |
| 71 | } | 70 | } |
| 72 | }.make); | 71 | }.make); |
| 73 | return s; | 72 | return s; |
| @@ -296,10 +296,10 @@ pub fn helpFull( | |||
| 296 | continue; | 296 | continue; |
| 297 | 297 | ||
| 298 | var counting_stream = io.CountingOutStream(@typeOf(stream.*).Error).init(stream); | 298 | var counting_stream = io.CountingOutStream(@typeOf(stream.*).Error).init(stream); |
| 299 | try stream.print("\t"); | 299 | try stream.print("\t", .{}); |
| 300 | try printParam(&counting_stream.stream, Id, param, Error, context, value_text); | 300 | try printParam(&counting_stream.stream, Id, param, Error, context, value_text); |
| 301 | try stream.writeByteNTimes(' ', max_spacing - counting_stream.bytes_written); | 301 | try stream.writeByteNTimes(' ', max_spacing - counting_stream.bytes_written); |
| 302 | try stream.print("\t{}\n", try help_text(context, param)); | 302 | try stream.print("\t{}\n", .{ try help_text(context, param) }); |
| 303 | } | 303 | } |
| 304 | } | 304 | } |
| 305 | 305 | ||
| @@ -312,21 +312,21 @@ fn printParam( | |||
| 312 | value_text: fn (@typeOf(context), Param(Id)) Error![]const u8, | 312 | value_text: fn (@typeOf(context), Param(Id)) Error![]const u8, |
| 313 | ) @typeOf(stream.*).Error!void { | 313 | ) @typeOf(stream.*).Error!void { |
| 314 | if (param.names.short) |s| { | 314 | if (param.names.short) |s| { |
| 315 | try stream.print("-{c}", s); | 315 | try stream.print("-{c}", .{ s }); |
| 316 | } else { | 316 | } else { |
| 317 | try stream.print(" "); | 317 | try stream.print(" ", .{}); |
| 318 | } | 318 | } |
| 319 | if (param.names.long) |l| { | 319 | if (param.names.long) |l| { |
| 320 | if (param.names.short) |_| { | 320 | if (param.names.short) |_| { |
| 321 | try stream.print(", "); | 321 | try stream.print(", ", .{}); |
| 322 | } else { | 322 | } else { |
| 323 | try stream.print(" "); | 323 | try stream.print(" ", .{}); |
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | try stream.print("--{}", l); | 326 | try stream.print("--{}", .{ l }); |
| 327 | } | 327 | } |
| 328 | if (param.takes_value) | 328 | if (param.takes_value) |
| 329 | try stream.print(" <{}>", value_text(context, param)); | 329 | try stream.print(" <{}>", .{ value_text(context, param) }); |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | /// A wrapper around helpFull for simple help_text and value_text functions that | 332 | /// A wrapper around helpFull for simple help_text and value_text functions that |
| @@ -414,18 +414,18 @@ test "clap.help" { | |||
| 414 | 414 | ||
| 415 | const actual = slice_stream.getWritten(); | 415 | const actual = slice_stream.getWritten(); |
| 416 | if (!mem.eql(u8, actual, expected)) { | 416 | if (!mem.eql(u8, actual, expected)) { |
| 417 | debug.warn("\n============ Expected ============\n"); | 417 | debug.warn("\n============ Expected ============\n", .{}); |
| 418 | debug.warn("{}", expected); | 418 | debug.warn("{}", .{ expected }); |
| 419 | debug.warn("============= Actual =============\n"); | 419 | debug.warn("============= Actual =============\n", .{}); |
| 420 | debug.warn("{}", actual); | 420 | debug.warn("{}", .{ actual }); |
| 421 | 421 | ||
| 422 | var buffer: [1024 * 2]u8 = undefined; | 422 | var buffer: [1024 * 2]u8 = undefined; |
| 423 | var fba = std.heap.FixedBufferAllocator.init(&buffer); | 423 | var fba = std.heap.FixedBufferAllocator.init(&buffer); |
| 424 | 424 | ||
| 425 | debug.warn("============ Expected (escaped) ============\n"); | 425 | debug.warn("============ Expected (escaped) ============\n", .{}); |
| 426 | debug.warn("{x}\n", expected); | 426 | debug.warn("{x}\n", .{ expected }); |
| 427 | debug.warn("============ Actual (escaped) ============\n"); | 427 | debug.warn("============ Actual (escaped) ============\n", .{}); |
| 428 | debug.warn("{x}\n", actual); | 428 | debug.warn("{x}\n", .{ actual }); |
| 429 | testing.expect(false); | 429 | testing.expect(false); |
| 430 | } | 430 | } |
| 431 | } | 431 | } |
diff --git a/example/comptime-clap.zig b/example/comptime-clap.zig index fde0648..a030368 100644 --- a/example/comptime-clap.zig +++ b/example/comptime-clap.zig | |||
| @@ -26,9 +26,9 @@ 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.warn("--help\n", .{}); |
| 30 | if (args.option("--number")) |n| | 30 | if (args.option("--number")) |n| |
| 31 | debug.warn("--number = {}\n", n); | 31 | debug.warn("--number = {}\n", .{ n }); |
| 32 | for (args.positionals()) |pos| | 32 | for (args.positionals()) |pos| |
| 33 | debug.warn("{}\n", pos); | 33 | debug.warn("{}\n", .{ pos }); |
| 34 | } | 34 | } |
diff --git a/example/simple.zig b/example/simple.zig index a3f27ea..5ac204d 100644 --- a/example/simple.zig +++ b/example/simple.zig | |||
| @@ -18,9 +18,9 @@ pub fn main() !void { | |||
| 18 | defer args.deinit(); | 18 | defer args.deinit(); |
| 19 | 19 | ||
| 20 | if (args.flag("--help")) | 20 | if (args.flag("--help")) |
| 21 | debug.warn("--help\n"); | 21 | debug.warn("--help\n", .{}); |
| 22 | if (args.option("--number")) |n| | 22 | if (args.option("--number")) |n| |
| 23 | debug.warn("--number = {}\n", n); | 23 | debug.warn("--number = {}\n", .{ n }); |
| 24 | for (args.positionals()) |pos| | 24 | for (args.positionals()) |pos| |
| 25 | debug.warn("{}\n", pos); | 25 | debug.warn("{}\n", .{ pos }); |
| 26 | } | 26 | } |
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index c9f20e2..b277266 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -38,13 +38,13 @@ pub fn main() !void { | |||
| 38 | while (try parser.next()) |arg| { | 38 | while (try parser.next()) |arg| { |
| 39 | // arg.param will point to the parameter which matched the argument. | 39 | // arg.param will point to the parameter which matched the argument. |
| 40 | switch (arg.param.id) { | 40 | switch (arg.param.id) { |
| 41 | 'h' => debug.warn("Help!\n"), | 41 | 'h' => debug.warn("Help!\n", .{}), |
| 42 | 'n' => debug.warn("--number = {}\n", arg.value.?), | 42 | 'n' => debug.warn("--number = {}\n", .{ arg.value.? }), |
| 43 | 43 | ||
| 44 | // arg.value == null, if arg.param.takes_value == false. | 44 | // arg.value == null, if arg.param.takes_value == false. |
| 45 | // Otherwise, arg.value is the value passed with the argument, such as "-a=10" | 45 | // Otherwise, arg.value is the value passed with the argument, such as "-a=10" |
| 46 | // or "-a 10". | 46 | // or "-a 10". |
| 47 | 'f' => debug.warn("{}\n", arg.value.?), | 47 | 'f' => debug.warn("{}\n", .{ arg.value.? }), |
| 48 | else => unreachable, | 48 | else => unreachable, |
| 49 | } | 49 | } |
| 50 | } | 50 | } |