diff options
| -rw-r--r-- | clap.zig | 28 | ||||
| -rw-r--r-- | example/simple-ex.zig | 4 | ||||
| -rw-r--r-- | example/streaming-clap.zig | 4 |
3 files changed, 22 insertions, 14 deletions
| @@ -219,10 +219,10 @@ pub const Diagnostic = struct { | |||
| 219 | Arg{ .prefix = "", .name = diag.arg }; | 219 | Arg{ .prefix = "", .name = diag.arg }; |
| 220 | 220 | ||
| 221 | switch (err) { | 221 | switch (err) { |
| 222 | error.DoesntTakeValue => try stream.print("The argument '{}{}' does not take a value\n", .{ a.prefix, a.name }), | 222 | error.DoesntTakeValue => try stream.print("The argument '{s}{s}' does not take a value\n", .{ a.prefix, a.name }), |
| 223 | error.MissingValue => try stream.print("The argument '{}{}' requires a value but none was supplied\n", .{ a.prefix, a.name }), | 223 | error.MissingValue => try stream.print("The argument '{s}{s}' requires a value but none was supplied\n", .{ a.prefix, a.name }), |
| 224 | error.InvalidArgument => try stream.print("Invalid argument '{}{}'\n", .{ a.prefix, a.name }), | 224 | error.InvalidArgument => try stream.print("Invalid argument '{s}{s}'\n", .{ a.prefix, a.name }), |
| 225 | else => try stream.print("Error while parsing arguments: {}\n", .{@errorName(err)}), | 225 | else => try stream.print("Error while parsing arguments: {s}\n", .{@errorName(err)}), |
| 226 | } | 226 | } |
| 227 | } | 227 | } |
| 228 | }; | 228 | }; |
| @@ -338,7 +338,7 @@ pub fn helpFull( | |||
| 338 | const max_spacing = blk: { | 338 | const max_spacing = blk: { |
| 339 | var res: usize = 0; | 339 | var res: usize = 0; |
| 340 | for (params) |param| { | 340 | for (params) |param| { |
| 341 | var cs = io.countingOutStream(io.null_out_stream); | 341 | var cs = io.countingOutStream(io.null_writer); |
| 342 | try printParam(cs.writer(), Id, param, Error, context, valueText); | 342 | try printParam(cs.writer(), Id, param, Error, context, valueText); |
| 343 | if (res < cs.bytes_written) | 343 | if (res < cs.bytes_written) |
| 344 | res = @intCast(usize, cs.bytes_written); | 344 | res = @intCast(usize, cs.bytes_written); |
| @@ -351,7 +351,7 @@ pub fn helpFull( | |||
| 351 | if (param.names.short == null and param.names.long == null) | 351 | if (param.names.short == null and param.names.long == null) |
| 352 | continue; | 352 | continue; |
| 353 | 353 | ||
| 354 | var cs = io.countingOutStream(stream); | 354 | var cs = io.countingWriter(stream); |
| 355 | try stream.print("\t", .{}); | 355 | try stream.print("\t", .{}); |
| 356 | try printParam(cs.writer(), Id, param, Error, context, valueText); | 356 | try printParam(cs.writer(), Id, param, Error, context, valueText); |
| 357 | try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, cs.bytes_written)); | 357 | try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, cs.bytes_written)); |
| @@ -379,13 +379,13 @@ fn printParam( | |||
| 379 | try stream.print(" ", .{}); | 379 | try stream.print(" ", .{}); |
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | try stream.print("--{}", .{l}); | 382 | try stream.print("--{s}", .{l}); |
| 383 | } | 383 | } |
| 384 | 384 | ||
| 385 | switch (param.takes_value) { | 385 | switch (param.takes_value) { |
| 386 | .none => {}, | 386 | .none => {}, |
| 387 | .one => try stream.print(" <{}>", .{valueText(context, param)}), | 387 | .one => try stream.print(" <{s}>", .{valueText(context, param)}), |
| 388 | .many => try stream.print(" <{}>...", .{valueText(context, param)}), | 388 | .many => try stream.print(" <{s}>...", .{valueText(context, param)}), |
| 389 | } | 389 | } |
| 390 | } | 390 | } |
| 391 | 391 | ||
| @@ -487,7 +487,7 @@ pub fn usageFull( | |||
| 487 | context: anytype, | 487 | context: anytype, |
| 488 | valueText: fn (@TypeOf(context), Param(Id)) Error![]const u8, | 488 | valueText: fn (@TypeOf(context), Param(Id)) Error![]const u8, |
| 489 | ) !void { | 489 | ) !void { |
| 490 | var cos = io.countingOutStream(stream); | 490 | var cos = io.countingWriter(stream); |
| 491 | const cs = cos.writer(); | 491 | const cs = cos.writer(); |
| 492 | for (params) |param| { | 492 | for (params) |param| { |
| 493 | const name = param.names.short orelse continue; | 493 | const name = param.names.short orelse continue; |
| @@ -517,11 +517,11 @@ pub fn usageFull( | |||
| 517 | if (cos.bytes_written != 0) | 517 | if (cos.bytes_written != 0) |
| 518 | try cs.writeByte(' '); | 518 | try cs.writeByte(' '); |
| 519 | 519 | ||
| 520 | try cs.print("[{}{}", .{ prefix, name }); | 520 | try cs.print("[{s}{s}", .{ prefix, name }); |
| 521 | switch (param.takes_value) { | 521 | switch (param.takes_value) { |
| 522 | .none => {}, | 522 | .none => {}, |
| 523 | .one => try cs.print(" <{}>", .{try valueText(context, param)}), | 523 | .one => try cs.print(" <{s}>", .{try valueText(context, param)}), |
| 524 | .many => try cs.print(" <{}>...", .{try valueText(context, param)}), | 524 | .many => try cs.print(" <{s}>...", .{try valueText(context, param)}), |
| 525 | } | 525 | } |
| 526 | 526 | ||
| 527 | try cs.writeByte(']'); | 527 | try cs.writeByte(']'); |
| @@ -530,7 +530,7 @@ pub fn usageFull( | |||
| 530 | if (positional) |p| { | 530 | if (positional) |p| { |
| 531 | if (cos.bytes_written != 0) | 531 | if (cos.bytes_written != 0) |
| 532 | try cs.writeByte(' '); | 532 | try cs.writeByte(' '); |
| 533 | try cs.print("<{}>", .{try valueText(context, p)}); | 533 | try cs.print("<{s}>", .{try valueText(context, p)}); |
| 534 | } | 534 | } |
| 535 | } | 535 | } |
| 536 | 536 | ||
diff --git a/example/simple-ex.zig b/example/simple-ex.zig index f08751b..88598aa 100644 --- a/example/simple-ex.zig +++ b/example/simple-ex.zig | |||
| @@ -30,7 +30,11 @@ pub fn main() !void { | |||
| 30 | .diagnostic = &diag, | 30 | .diagnostic = &diag, |
| 31 | }) catch |err| { | 31 | }) catch |err| { |
| 32 | // Report useful error and exit | 32 | // Report useful error and exit |
| 33 | <<<<<<< HEAD | ||
| 34 | diag.report(std.io.getStdErr().writer(), err) catch {}; | ||
| 35 | ======= | ||
| 33 | diag.report(io.getStdErr().writer(), err) catch {}; | 36 | diag.report(io.getStdErr().writer(), err) catch {}; |
| 37 | >>>>>>> master | ||
| 34 | return err; | 38 | return err; |
| 35 | }; | 39 | }; |
| 36 | defer args.deinit(); | 40 | defer args.deinit(); |
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index 41efd1f..32d44c4 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -39,7 +39,11 @@ pub fn main() !void { | |||
| 39 | // Because we use a streaming parser, we have to consume each argument parsed individually. | 39 | // Because we use a streaming parser, we have to consume each argument parsed individually. |
| 40 | while (parser.next() catch |err| { | 40 | while (parser.next() catch |err| { |
| 41 | // Report useful error and exit | 41 | // Report useful error and exit |
| 42 | <<<<<<< HEAD | ||
| 43 | diag.report(std.io.getStdErr().writer(), err) catch {}; | ||
| 44 | ======= | ||
| 42 | diag.report(io.getStdErr().writer(), err) catch {}; | 45 | diag.report(io.getStdErr().writer(), err) catch {}; |
| 46 | >>>>>>> master | ||
| 43 | return err; | 47 | return err; |
| 44 | }) |arg| { | 48 | }) |arg| { |
| 45 | // arg.param will point to the parameter which matched the argument. | 49 | // arg.param will point to the parameter which matched the argument. |