From 3c35ff18bb32fec2f53e12e6bdbb00422d6c33fe Mon Sep 17 00:00:00 2001 From: Takumi Katase Date: Fri, 2 Jan 2026 20:59:20 +0900 Subject: chore: update examples to use std.Io for Zig v0.16 compatibility Signed-off-by: Takumi Katase --- example/help.zig | 4 +++- example/simple-ex.zig | 5 ++++- example/simple.zig | 4 +++- example/streaming-clap.zig | 5 ++++- example/subcommands.zig | 9 +++++++-- example/usage.zig | 5 ++++- 6 files changed, 25 insertions(+), 7 deletions(-) (limited to 'example') diff --git a/example/help.zig b/example/help.zig index d8e8f12..a4379de 100644 --- a/example/help.zig +++ b/example/help.zig @@ -13,12 +13,14 @@ pub fn main() !void { }); defer res.deinit(); + var threaded: std.Io.Threaded = .init_single_threaded; + const io: std.Io = threaded.io(); // `clap.help` is a function that can print a simple help message. It can print any `Param` // where `Id` has a `description` and `value` method (`Param(Help)` is one such parameter). // The last argument contains options as to how `help` should print those parameters. Using // `.{}` means the default options. if (res.args.help != 0) - return clap.helpToFile(.stderr(), clap.Help, ¶ms, .{}); + return clap.helpToFile(io, .stderr(), clap.Help, ¶ms, .{}); } const clap = @import("clap"); diff --git a/example/simple-ex.zig b/example/simple-ex.zig index 912c75b..7ab8d1e 100644 --- a/example/simple-ex.zig +++ b/example/simple-ex.zig @@ -23,6 +23,9 @@ pub fn main() !void { .ANSWER = clap.parsers.enumeration(YesNo), }; + var threaded: std.Io.Threaded = .init_single_threaded; + const io: std.Io = threaded.io(); + var diag = clap.Diagnostic{}; var res = clap.parse(clap.Help, ¶ms, parsers, .{ .diagnostic = &diag, @@ -32,7 +35,7 @@ pub fn main() !void { .assignment_separators = "=:", }) catch |err| { // Report useful error and exit. - try diag.reportToFile(.stderr(), err); + try diag.reportToFile(io, .stderr(), err); return err; }; defer res.deinit(); diff --git a/example/simple.zig b/example/simple.zig index abcf448..67313aa 100644 --- a/example/simple.zig +++ b/example/simple.zig @@ -16,12 +16,14 @@ pub fn main() !void { // This is optional. You can also pass `.{}` to `clap.parse` if you don't // care about the extra information `Diagnostics` provides. var diag = clap.Diagnostic{}; + var threaded: std.Io.Threaded = .init_single_threaded; + const io: std.Io = threaded.io(); var res = clap.parse(clap.Help, ¶ms, clap.parsers.default, .{ .diagnostic = &diag, .allocator = gpa.allocator(), }) catch |err| { // Report useful error and exit. - try diag.reportToFile(.stderr(), err); + try diag.reportToFile(io, .stderr(), err); return err; }; defer res.deinit(); diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index 4cd6962..c58cd24 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig @@ -31,10 +31,13 @@ pub fn main() !void { .diagnostic = &diag, }; + var threaded: std.Io.Threaded = .init_single_threaded; + const io: std.Io = threaded.io(); + // Because we use a streaming parser, we have to consume each argument parsed individually. while (parser.next() catch |err| { // Report useful error and exit. - try diag.reportToFile(.stderr(), err); + try diag.reportToFile(io, .stderr(), err); return err; }) |arg| { // arg.param will point to the parameter which matched the argument. diff --git a/example/subcommands.zig b/example/subcommands.zig index 5c3e7c7..6eb919b 100644 --- a/example/subcommands.zig +++ b/example/subcommands.zig @@ -29,6 +29,9 @@ pub fn main() !void { _ = iter.next(); + var threaded: std.Io.Threaded = .init_single_threaded; + const io: std.Io = threaded.io(); + var diag = clap.Diagnostic{}; var res = clap.parseEx(clap.Help, &main_params, main_parsers, &iter, .{ .diagnostic = &diag, @@ -41,7 +44,7 @@ pub fn main() !void { // not fully consumed. It can then be reused to parse the arguments for subcommands. .terminating_positional = 0, }) catch |err| { - try diag.reportToFile(.stderr(), err); + try diag.reportToFile(io, .stderr(), err); return err; }; defer res.deinit(); @@ -73,11 +76,13 @@ fn mathMain(gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: M // Here we pass the partially parsed argument iterator. var diag = clap.Diagnostic{}; + var threaded: std.Io.Threaded = .init_single_threaded; + const io: std.Io = threaded.io(); var res = clap.parseEx(clap.Help, ¶ms, clap.parsers.default, iter, .{ .diagnostic = &diag, .allocator = gpa, }) catch |err| { - try diag.reportToFile(.stderr(), err); + try diag.reportToFile(io, .stderr(), err); return err; // propagate error }; defer res.deinit(); diff --git a/example/usage.zig b/example/usage.zig index aab9cb6..c1440b9 100644 --- a/example/usage.zig +++ b/example/usage.zig @@ -14,10 +14,13 @@ pub fn main() !void { }); defer res.deinit(); + var threaded: std.Io.Threaded = .init_single_threaded; + const io: std.Io = threaded.io(); + // `clap.usageToFile` is a function that can print a simple usage string. It can print any // `Param` where `Id` has a `value` method (`Param(Help)` is one such parameter). if (res.args.help != 0) - return clap.usageToFile(.stdout(), clap.Help, ¶ms); + return clap.usageToFile(io, .stdout(), clap.Help, ¶ms); } const clap = @import("clap"); -- cgit v1.2.3