diff options
Diffstat (limited to 'clap.zig')
| -rw-r--r-- | clap.zig | 42 |
1 files changed, 21 insertions, 21 deletions
| @@ -272,10 +272,10 @@ pub const Diagnostic = struct { | |||
| 272 | Arg{ .prefix = "", .name = diag.arg }; | 272 | Arg{ .prefix = "", .name = diag.arg }; |
| 273 | 273 | ||
| 274 | switch (err) { | 274 | switch (err) { |
| 275 | error.DoesntTakeValue => try stream.print("The argument '{}{}' does not take a value\n", .{ a.prefix, a.name }), | 275 | error.DoesntTakeValue => try stream.print("The argument '{s}{s}' does not take a value\n", .{ a.prefix, a.name }), |
| 276 | error.MissingValue => try stream.print("The argument '{}{}' requires a value but none was supplied\n", .{ a.prefix, a.name }), | 276 | error.MissingValue => try stream.print("The argument '{s}{s}' requires a value but none was supplied\n", .{ a.prefix, a.name }), |
| 277 | error.InvalidArgument => try stream.print("Invalid argument '{}{}'\n", .{ a.prefix, a.name }), | 277 | error.InvalidArgument => try stream.print("Invalid argument '{s}{s}'\n", .{ a.prefix, a.name }), |
| 278 | else => try stream.print("Error while parsing arguments: {}\n", .{@errorName(err)}), | 278 | else => try stream.print("Error while parsing arguments: {s}\n", .{@errorName(err)}), |
| 279 | } | 279 | } |
| 280 | } | 280 | } |
| 281 | }; | 281 | }; |
| @@ -283,7 +283,7 @@ pub const Diagnostic = struct { | |||
| 283 | fn testDiag(diag: Diagnostic, err: anyerror, expected: []const u8) void { | 283 | fn testDiag(diag: Diagnostic, err: anyerror, expected: []const u8) void { |
| 284 | var buf: [1024]u8 = undefined; | 284 | var buf: [1024]u8 = undefined; |
| 285 | var slice_stream = io.fixedBufferStream(&buf); | 285 | var slice_stream = io.fixedBufferStream(&buf); |
| 286 | diag.report(slice_stream.outStream(), err) catch unreachable; | 286 | diag.report(slice_stream.writer(), err) catch unreachable; |
| 287 | testing.expectEqualStrings(expected, slice_stream.getWritten()); | 287 | testing.expectEqualStrings(expected, slice_stream.getWritten()); |
| 288 | } | 288 | } |
| 289 | 289 | ||
| @@ -376,8 +376,8 @@ pub fn helpFull( | |||
| 376 | const max_spacing = blk: { | 376 | const max_spacing = blk: { |
| 377 | var res: usize = 0; | 377 | var res: usize = 0; |
| 378 | for (params) |param| { | 378 | for (params) |param| { |
| 379 | var counting_stream = io.countingOutStream(io.null_out_stream); | 379 | var counting_stream = io.countingWriter(io.null_writer); |
| 380 | try printParam(counting_stream.outStream(), Id, param, Error, context, valueText); | 380 | try printParam(counting_stream.writer(), Id, param, Error, context, valueText); |
| 381 | if (res < counting_stream.bytes_written) | 381 | if (res < counting_stream.bytes_written) |
| 382 | res = @intCast(usize, counting_stream.bytes_written); | 382 | res = @intCast(usize, counting_stream.bytes_written); |
| 383 | } | 383 | } |
| @@ -389,11 +389,11 @@ pub fn helpFull( | |||
| 389 | if (param.names.short == null and param.names.long == null) | 389 | if (param.names.short == null and param.names.long == null) |
| 390 | continue; | 390 | continue; |
| 391 | 391 | ||
| 392 | var counting_stream = io.countingOutStream(stream); | 392 | var counting_stream = io.countingWriter(stream); |
| 393 | try stream.print("\t", .{}); | 393 | try stream.print("\t", .{}); |
| 394 | try printParam(counting_stream.outStream(), Id, param, Error, context, valueText); | 394 | try printParam(counting_stream.writer(), Id, param, Error, context, valueText); |
| 395 | try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, counting_stream.bytes_written)); | 395 | try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, counting_stream.bytes_written)); |
| 396 | try stream.print("\t{}\n", .{try helpText(context, param)}); | 396 | try stream.print("\t{s}\n", .{try helpText(context, param)}); |
| 397 | } | 397 | } |
| 398 | } | 398 | } |
| 399 | 399 | ||
| @@ -417,13 +417,13 @@ fn printParam( | |||
| 417 | try stream.print(" ", .{}); | 417 | try stream.print(" ", .{}); |
| 418 | } | 418 | } |
| 419 | 419 | ||
| 420 | try stream.print("--{}", .{l}); | 420 | try stream.print("--{s}", .{l}); |
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | switch (param.takes_value) { | 423 | switch (param.takes_value) { |
| 424 | .None => {}, | 424 | .None => {}, |
| 425 | .One => try stream.print(" <{}>", .{valueText(context, param)}), | 425 | .One => try stream.print(" <{s}>", .{valueText(context, param)}), |
| 426 | .Many => try stream.print(" <{}>...", .{valueText(context, param)}), | 426 | .Many => try stream.print(" <{s}>...", .{valueText(context, param)}), |
| 427 | } | 427 | } |
| 428 | } | 428 | } |
| 429 | 429 | ||
| @@ -487,7 +487,7 @@ test "clap.help" { | |||
| 487 | 487 | ||
| 488 | @setEvalBranchQuota(10000); | 488 | @setEvalBranchQuota(10000); |
| 489 | try help( | 489 | try help( |
| 490 | slice_stream.outStream(), | 490 | slice_stream.writer(), |
| 491 | comptime &[_]Param(Help){ | 491 | comptime &[_]Param(Help){ |
| 492 | parseParam("-a Short flag. ") catch unreachable, | 492 | parseParam("-a Short flag. ") catch unreachable, |
| 493 | parseParam("-b <V1> Short option.") catch unreachable, | 493 | parseParam("-b <V1> Short option.") catch unreachable, |
| @@ -530,8 +530,8 @@ pub fn usageFull( | |||
| 530 | context: anytype, | 530 | context: anytype, |
| 531 | valueText: fn (@TypeOf(context), Param(Id)) Error![]const u8, | 531 | valueText: fn (@TypeOf(context), Param(Id)) Error![]const u8, |
| 532 | ) !void { | 532 | ) !void { |
| 533 | var cos = io.countingOutStream(stream); | 533 | var cos = io.countingWriter(stream); |
| 534 | const cs = cos.outStream(); | 534 | const cs = cos.writer(); |
| 535 | for (params) |param| { | 535 | for (params) |param| { |
| 536 | const name = param.names.short orelse continue; | 536 | const name = param.names.short orelse continue; |
| 537 | if (param.takes_value != .None) | 537 | if (param.takes_value != .None) |
| @@ -560,11 +560,11 @@ pub fn usageFull( | |||
| 560 | if (cos.bytes_written != 0) | 560 | if (cos.bytes_written != 0) |
| 561 | try cs.writeByte(' '); | 561 | try cs.writeByte(' '); |
| 562 | 562 | ||
| 563 | try cs.print("[{}{}", .{ prefix, name }); | 563 | try cs.print("[{s}{s}", .{ prefix, name }); |
| 564 | switch (param.takes_value) { | 564 | switch (param.takes_value) { |
| 565 | .None => {}, | 565 | .None => {}, |
| 566 | .One => try cs.print(" <{}>", .{try valueText(context, param)}), | 566 | .One => try cs.print(" <{s}>", .{try valueText(context, param)}), |
| 567 | .Many => try cs.print(" <{}>...", .{try valueText(context, param)}), | 567 | .Many => try cs.print(" <{s}>...", .{try valueText(context, param)}), |
| 568 | } | 568 | } |
| 569 | 569 | ||
| 570 | try cs.writeByte(']'); | 570 | try cs.writeByte(']'); |
| @@ -573,7 +573,7 @@ pub fn usageFull( | |||
| 573 | if (positional) |p| { | 573 | if (positional) |p| { |
| 574 | if (cos.bytes_written != 0) | 574 | if (cos.bytes_written != 0) |
| 575 | try cs.writeByte(' '); | 575 | try cs.writeByte(' '); |
| 576 | try cs.print("<{}>", .{try valueText(context, p)}); | 576 | try cs.print("<{s}>", .{try valueText(context, p)}); |
| 577 | } | 577 | } |
| 578 | } | 578 | } |
| 579 | 579 | ||
| @@ -611,7 +611,7 @@ pub fn usage(stream: anytype, params: []const Param(Help)) !void { | |||
| 611 | fn testUsage(expected: []const u8, params: []const Param(Help)) !void { | 611 | fn testUsage(expected: []const u8, params: []const Param(Help)) !void { |
| 612 | var buf: [1024]u8 = undefined; | 612 | var buf: [1024]u8 = undefined; |
| 613 | var fbs = io.fixedBufferStream(&buf); | 613 | var fbs = io.fixedBufferStream(&buf); |
| 614 | try usage(fbs.outStream(), params); | 614 | try usage(fbs.writer(), params); |
| 615 | testing.expectEqualStrings(expected, fbs.getWritten()); | 615 | testing.expectEqualStrings(expected, fbs.getWritten()); |
| 616 | } | 616 | } |
| 617 | 617 | ||