From fb1eb05c2114123fff3981923bacfb74ac6b03ae Mon Sep 17 00:00:00 2001 From: Asherah Connor Date: Sun, 10 Jan 2021 12:34:39 +1100 Subject: zig master updates --- README.md | 8 ++++---- build.zig | 2 +- clap.zig | 42 +++++++++++++++++++++--------------------- clap/streaming.zig | 2 +- example/help.zig | 2 +- example/simple-ex.zig | 2 +- example/simple.zig | 2 +- example/streaming-clap.zig | 2 +- example/usage.zig | 2 +- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 3156539..23c2672 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ pub fn main() !void { var args = clap.parse(clap.Help, ¶ms, std.heap.page_allocator, &diag) catch |err| { // Report useful error and exit - diag.report(std.io.getStdErr().outStream(), err) catch {}; + diag.report(std.io.getStdErr().writer(), err) catch {}; return err; }; defer args.deinit(); @@ -151,7 +151,7 @@ pub fn main() !void { // Because we use a streaming parser, we have to consume each argument parsed individually. while (parser.next(&diag) catch |err| { // Report useful error and exit - diag.report(std.io.getStdErr().outStream(), err) catch {}; + diag.report(std.io.getStdErr().writer(), err) catch {}; return err; }) |arg| { // arg.param will point to the parameter which matched the argument. @@ -184,7 +184,7 @@ const clap = @import("clap"); pub fn main() !void { const stderr_file = std.io.getStdErr(); - var stderr_out_stream = stderr_file.outStream(); + var stderr_out_stream = stderr_file.writer(); // clap.help is a function that can print a simple help message, given a // slice of Param(Help). There is also a helpEx, which can print a @@ -224,7 +224,7 @@ const std = @import("std"); const clap = @import("clap"); pub fn main() !void { - const stderr = std.io.getStdErr().outStream(); + const stderr = std.io.getStdErr().writer(); // clap.usage is a function that can print a simple usage message, given a // slice of Param(Help). There is also a usageEx, which can print a diff --git a/build.zig b/build.zig index c32f4c2..a5f3eb6 100644 --- a/build.zig +++ b/build.zig @@ -66,7 +66,7 @@ fn readMeStep(b: *Builder) *std.build.Step { fn make(step: *std.build.Step) anyerror!void { @setEvalBranchQuota(10000); const file = try std.fs.cwd().createFile("README.md", .{}); - const stream = &file.outStream(); + const stream = &file.writer(); try stream.print(@embedFile("example/README.md.template"), .{ @embedFile("example/simple.zig"), @embedFile("example/simple-error.zig"), diff --git a/clap.zig b/clap.zig index 4548a48..be2153f 100644 --- a/clap.zig +++ b/clap.zig @@ -272,10 +272,10 @@ pub const Diagnostic = struct { Arg{ .prefix = "", .name = diag.arg }; switch (err) { - error.DoesntTakeValue => try stream.print("The argument '{}{}' does not take a value\n", .{ a.prefix, a.name }), - error.MissingValue => try stream.print("The argument '{}{}' requires a value but none was supplied\n", .{ a.prefix, a.name }), - error.InvalidArgument => try stream.print("Invalid argument '{}{}'\n", .{ a.prefix, a.name }), - else => try stream.print("Error while parsing arguments: {}\n", .{@errorName(err)}), + error.DoesntTakeValue => try stream.print("The argument '{s}{s}' does not take a value\n", .{ a.prefix, a.name }), + error.MissingValue => try stream.print("The argument '{s}{s}' requires a value but none was supplied\n", .{ a.prefix, a.name }), + error.InvalidArgument => try stream.print("Invalid argument '{s}{s}'\n", .{ a.prefix, a.name }), + else => try stream.print("Error while parsing arguments: {s}\n", .{@errorName(err)}), } } }; @@ -283,7 +283,7 @@ pub const Diagnostic = struct { fn testDiag(diag: Diagnostic, err: anyerror, expected: []const u8) void { var buf: [1024]u8 = undefined; var slice_stream = io.fixedBufferStream(&buf); - diag.report(slice_stream.outStream(), err) catch unreachable; + diag.report(slice_stream.writer(), err) catch unreachable; testing.expectEqualStrings(expected, slice_stream.getWritten()); } @@ -376,8 +376,8 @@ pub fn helpFull( const max_spacing = blk: { var res: usize = 0; for (params) |param| { - var counting_stream = io.countingOutStream(io.null_out_stream); - try printParam(counting_stream.outStream(), Id, param, Error, context, valueText); + var counting_stream = io.countingWriter(io.null_writer); + try printParam(counting_stream.writer(), Id, param, Error, context, valueText); if (res < counting_stream.bytes_written) res = @intCast(usize, counting_stream.bytes_written); } @@ -389,11 +389,11 @@ pub fn helpFull( if (param.names.short == null and param.names.long == null) continue; - var counting_stream = io.countingOutStream(stream); + var counting_stream = io.countingWriter(stream); try stream.print("\t", .{}); - try printParam(counting_stream.outStream(), Id, param, Error, context, valueText); + try printParam(counting_stream.writer(), Id, param, Error, context, valueText); try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, counting_stream.bytes_written)); - try stream.print("\t{}\n", .{try helpText(context, param)}); + try stream.print("\t{s}\n", .{try helpText(context, param)}); } } @@ -417,13 +417,13 @@ fn printParam( try stream.print(" ", .{}); } - try stream.print("--{}", .{l}); + try stream.print("--{s}", .{l}); } switch (param.takes_value) { .None => {}, - .One => try stream.print(" <{}>", .{valueText(context, param)}), - .Many => try stream.print(" <{}>...", .{valueText(context, param)}), + .One => try stream.print(" <{s}>", .{valueText(context, param)}), + .Many => try stream.print(" <{s}>...", .{valueText(context, param)}), } } @@ -487,7 +487,7 @@ test "clap.help" { @setEvalBranchQuota(10000); try help( - slice_stream.outStream(), + slice_stream.writer(), comptime &[_]Param(Help){ parseParam("-a Short flag. ") catch unreachable, parseParam("-b Short option.") catch unreachable, @@ -530,8 +530,8 @@ pub fn usageFull( context: anytype, valueText: fn (@TypeOf(context), Param(Id)) Error![]const u8, ) !void { - var cos = io.countingOutStream(stream); - const cs = cos.outStream(); + var cos = io.countingWriter(stream); + const cs = cos.writer(); for (params) |param| { const name = param.names.short orelse continue; if (param.takes_value != .None) @@ -560,11 +560,11 @@ pub fn usageFull( if (cos.bytes_written != 0) try cs.writeByte(' '); - try cs.print("[{}{}", .{ prefix, name }); + try cs.print("[{s}{s}", .{ prefix, name }); switch (param.takes_value) { .None => {}, - .One => try cs.print(" <{}>", .{try valueText(context, param)}), - .Many => try cs.print(" <{}>...", .{try valueText(context, param)}), + .One => try cs.print(" <{s}>", .{try valueText(context, param)}), + .Many => try cs.print(" <{s}>...", .{try valueText(context, param)}), } try cs.writeByte(']'); @@ -573,7 +573,7 @@ pub fn usageFull( if (positional) |p| { if (cos.bytes_written != 0) try cs.writeByte(' '); - try cs.print("<{}>", .{try valueText(context, p)}); + try cs.print("<{s}>", .{try valueText(context, p)}); } } @@ -611,7 +611,7 @@ pub fn usage(stream: anytype, params: []const Param(Help)) !void { fn testUsage(expected: []const u8, params: []const Param(Help)) !void { var buf: [1024]u8 = undefined; var fbs = io.fixedBufferStream(&buf); - try usage(fbs.outStream(), params); + try usage(fbs.writer(), params); testing.expectEqualStrings(expected, fbs.getWritten()); } diff --git a/clap/streaming.zig b/clap/streaming.zig index 11145f0..0fe5aae 100644 --- a/clap/streaming.zig +++ b/clap/streaming.zig @@ -234,7 +234,7 @@ fn testErr(params: []const clap.Param(u8), args_strings: []const []const u8, exp while (c.next(&diag) catch |err| { var buf: [1024]u8 = undefined; var slice_stream = io.fixedBufferStream(&buf); - diag.report(slice_stream.outStream(), err) catch unreachable; + diag.report(slice_stream.writer(), err) catch unreachable; testing.expectEqualStrings(expected, slice_stream.getWritten()); return; }) |_| {} diff --git a/example/help.zig b/example/help.zig index 2775177..c210ff9 100644 --- a/example/help.zig +++ b/example/help.zig @@ -3,7 +3,7 @@ const clap = @import("clap"); pub fn main() !void { const stderr_file = std.io.getStdErr(); - var stderr_out_stream = stderr_file.outStream(); + var stderr_out_stream = stderr_file.writer(); // clap.help is a function that can print a simple help message, given a // slice of Param(Help). There is also a helpEx, which can print a diff --git a/example/simple-ex.zig b/example/simple-ex.zig index d6ecc44..b890860 100644 --- a/example/simple-ex.zig +++ b/example/simple-ex.zig @@ -27,7 +27,7 @@ pub fn main() !void { var args = clap.parseEx(clap.Help, ¶ms, allocator, &iter, &diag) catch |err| { // Report useful error and exit - diag.report(std.io.getStdErr().outStream(), err) catch {}; + diag.report(std.io.getStdErr().writer(), err) catch {}; return err; }; defer args.deinit(); diff --git a/example/simple.zig b/example/simple.zig index 270e344..559bba6 100644 --- a/example/simple.zig +++ b/example/simple.zig @@ -20,7 +20,7 @@ pub fn main() !void { var args = clap.parse(clap.Help, ¶ms, std.heap.page_allocator, &diag) catch |err| { // Report useful error and exit - diag.report(std.io.getStdErr().outStream(), err) catch {}; + diag.report(std.io.getStdErr().writer(), err) catch {}; return err; }; defer args.deinit(); diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index 941070f..5468fd5 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig @@ -42,7 +42,7 @@ pub fn main() !void { // Because we use a streaming parser, we have to consume each argument parsed individually. while (parser.next(&diag) catch |err| { // Report useful error and exit - diag.report(std.io.getStdErr().outStream(), err) catch {}; + diag.report(std.io.getStdErr().writer(), err) catch {}; return err; }) |arg| { // arg.param will point to the parameter which matched the argument. diff --git a/example/usage.zig b/example/usage.zig index 25e1a34..dc88c48 100644 --- a/example/usage.zig +++ b/example/usage.zig @@ -2,7 +2,7 @@ const std = @import("std"); const clap = @import("clap"); pub fn main() !void { - const stderr = std.io.getStdErr().outStream(); + const stderr = std.io.getStdErr().writer(); // clap.usage is a function that can print a simple usage message, given a // slice of Param(Help). There is also a usageEx, which can print a -- cgit v1.2.3