summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--README.md8
-rw-r--r--build.zig2
-rw-r--r--clap.zig42
-rw-r--r--clap/streaming.zig2
-rw-r--r--example/help.zig2
-rw-r--r--example/simple-ex.zig2
-rw-r--r--example/simple.zig2
-rw-r--r--example/streaming-clap.zig2
-rw-r--r--example/usage.zig2
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 {
47 47
48 var args = clap.parse(clap.Help, &params, std.heap.page_allocator, &diag) catch |err| { 48 var args = clap.parse(clap.Help, &params, std.heap.page_allocator, &diag) catch |err| {
49 // Report useful error and exit 49 // Report useful error and exit
50 diag.report(std.io.getStdErr().outStream(), err) catch {}; 50 diag.report(std.io.getStdErr().writer(), err) catch {};
51 return err; 51 return err;
52 }; 52 };
53 defer args.deinit(); 53 defer args.deinit();
@@ -151,7 +151,7 @@ pub fn main() !void {
151 // Because we use a streaming parser, we have to consume each argument parsed individually. 151 // Because we use a streaming parser, we have to consume each argument parsed individually.
152 while (parser.next(&diag) catch |err| { 152 while (parser.next(&diag) catch |err| {
153 // Report useful error and exit 153 // Report useful error and exit
154 diag.report(std.io.getStdErr().outStream(), err) catch {}; 154 diag.report(std.io.getStdErr().writer(), err) catch {};
155 return err; 155 return err;
156 }) |arg| { 156 }) |arg| {
157 // arg.param will point to the parameter which matched the argument. 157 // arg.param will point to the parameter which matched the argument.
@@ -184,7 +184,7 @@ const clap = @import("clap");
184 184
185pub fn main() !void { 185pub fn main() !void {
186 const stderr_file = std.io.getStdErr(); 186 const stderr_file = std.io.getStdErr();
187 var stderr_out_stream = stderr_file.outStream(); 187 var stderr_out_stream = stderr_file.writer();
188 188
189 // clap.help is a function that can print a simple help message, given a 189 // clap.help is a function that can print a simple help message, given a
190 // slice of Param(Help). There is also a helpEx, which can print a 190 // slice of Param(Help). There is also a helpEx, which can print a
@@ -224,7 +224,7 @@ const std = @import("std");
224const clap = @import("clap"); 224const clap = @import("clap");
225 225
226pub fn main() !void { 226pub fn main() !void {
227 const stderr = std.io.getStdErr().outStream(); 227 const stderr = std.io.getStdErr().writer();
228 228
229 // clap.usage is a function that can print a simple usage message, given a 229 // clap.usage is a function that can print a simple usage message, given a
230 // slice of Param(Help). There is also a usageEx, which can print a 230 // 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 {
66 fn make(step: *std.build.Step) anyerror!void { 66 fn make(step: *std.build.Step) anyerror!void {
67 @setEvalBranchQuota(10000); 67 @setEvalBranchQuota(10000);
68 const file = try std.fs.cwd().createFile("README.md", .{}); 68 const file = try std.fs.cwd().createFile("README.md", .{});
69 const stream = &file.outStream(); 69 const stream = &file.writer();
70 try stream.print(@embedFile("example/README.md.template"), .{ 70 try stream.print(@embedFile("example/README.md.template"), .{
71 @embedFile("example/simple.zig"), 71 @embedFile("example/simple.zig"),
72 @embedFile("example/simple-error.zig"), 72 @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 {
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 {
283fn testDiag(diag: Diagnostic, err: anyerror, expected: []const u8) void { 283fn 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 {
611fn testUsage(expected: []const u8, params: []const Param(Help)) !void { 611fn 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
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
234 while (c.next(&diag) catch |err| { 234 while (c.next(&diag) catch |err| {
235 var buf: [1024]u8 = undefined; 235 var buf: [1024]u8 = undefined;
236 var slice_stream = io.fixedBufferStream(&buf); 236 var slice_stream = io.fixedBufferStream(&buf);
237 diag.report(slice_stream.outStream(), err) catch unreachable; 237 diag.report(slice_stream.writer(), err) catch unreachable;
238 testing.expectEqualStrings(expected, slice_stream.getWritten()); 238 testing.expectEqualStrings(expected, slice_stream.getWritten());
239 return; 239 return;
240 }) |_| {} 240 }) |_| {}
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");
3 3
4pub fn main() !void { 4pub fn main() !void {
5 const stderr_file = std.io.getStdErr(); 5 const stderr_file = std.io.getStdErr();
6 var stderr_out_stream = stderr_file.outStream(); 6 var stderr_out_stream = stderr_file.writer();
7 7
8 // clap.help is a function that can print a simple help message, given a 8 // clap.help is a function that can print a simple help message, given a
9 // slice of Param(Help). There is also a helpEx, which can print a 9 // 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 {
27 27
28 var args = clap.parseEx(clap.Help, &params, allocator, &iter, &diag) catch |err| { 28 var args = clap.parseEx(clap.Help, &params, allocator, &iter, &diag) catch |err| {
29 // Report useful error and exit 29 // Report useful error and exit
30 diag.report(std.io.getStdErr().outStream(), err) catch {}; 30 diag.report(std.io.getStdErr().writer(), err) catch {};
31 return err; 31 return err;
32 }; 32 };
33 defer args.deinit(); 33 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 {
20 20
21 var args = clap.parse(clap.Help, &params, std.heap.page_allocator, &diag) catch |err| { 21 var args = clap.parse(clap.Help, &params, std.heap.page_allocator, &diag) catch |err| {
22 // Report useful error and exit 22 // Report useful error and exit
23 diag.report(std.io.getStdErr().outStream(), err) catch {}; 23 diag.report(std.io.getStdErr().writer(), err) catch {};
24 return err; 24 return err;
25 }; 25 };
26 defer args.deinit(); 26 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 {
42 // Because we use a streaming parser, we have to consume each argument parsed individually. 42 // Because we use a streaming parser, we have to consume each argument parsed individually.
43 while (parser.next(&diag) catch |err| { 43 while (parser.next(&diag) catch |err| {
44 // Report useful error and exit 44 // Report useful error and exit
45 diag.report(std.io.getStdErr().outStream(), err) catch {}; 45 diag.report(std.io.getStdErr().writer(), err) catch {};
46 return err; 46 return err;
47 }) |arg| { 47 }) |arg| {
48 // arg.param will point to the parameter which matched the argument. 48 // 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");
2const clap = @import("clap"); 2const clap = @import("clap");
3 3
4pub fn main() !void { 4pub fn main() !void {
5 const stderr = std.io.getStdErr().outStream(); 5 const stderr = std.io.getStdErr().writer();
6 6
7 // clap.usage is a function that can print a simple usage message, given a 7 // clap.usage is a function that can print a simple usage message, given a
8 // slice of Param(Help). There is also a usageEx, which can print a 8 // slice of Param(Help). There is also a usageEx, which can print a