summaryrefslogtreecommitdiff
path: root/example/subcommands.zig
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2026-01-07 21:01:09 +0100
committerGravatar Jimmi Holst Christensen2026-01-07 21:01:09 +0100
commit3b73a8edaff14039d917b1958715d1d54659851b (patch)
treea4c378b8678ba76685cfd4af3be2904b62104ab1 /example/subcommands.zig
parentchore: update minimum_zig_version (diff)
downloadzig-clap-3b73a8edaff14039d917b1958715d1d54659851b.tar.gz
zig-clap-3b73a8edaff14039d917b1958715d1d54659851b.tar.xz
zig-clap-3b73a8edaff14039d917b1958715d1d54659851b.zip
chore: Update examples in README to use new std.Io
Diffstat (limited to 'example/subcommands.zig')
-rw-r--r--example/subcommands.zig12
1 files changed, 5 insertions, 7 deletions
diff --git a/example/subcommands.zig b/example/subcommands.zig
index 6eb919b..bd8625b 100644
--- a/example/subcommands.zig
+++ b/example/subcommands.zig
@@ -24,14 +24,14 @@ pub fn main() !void {
24 const gpa = gpa_state.allocator(); 24 const gpa = gpa_state.allocator();
25 defer _ = gpa_state.deinit(); 25 defer _ = gpa_state.deinit();
26 26
27 var threaded: std.Io.Threaded = .init_single_threaded;
28 const io: std.Io = threaded.io();
29
27 var iter = try std.process.ArgIterator.initWithAllocator(gpa); 30 var iter = try std.process.ArgIterator.initWithAllocator(gpa);
28 defer iter.deinit(); 31 defer iter.deinit();
29 32
30 _ = iter.next(); 33 _ = iter.next();
31 34
32 var threaded: std.Io.Threaded = .init_single_threaded;
33 const io: std.Io = threaded.io();
34
35 var diag = clap.Diagnostic{}; 35 var diag = clap.Diagnostic{};
36 var res = clap.parseEx(clap.Help, &main_params, main_parsers, &iter, .{ 36 var res = clap.parseEx(clap.Help, &main_params, main_parsers, &iter, .{
37 .diagnostic = &diag, 37 .diagnostic = &diag,
@@ -55,11 +55,11 @@ pub fn main() !void {
55 const command = res.positionals[0] orelse return error.MissingCommand; 55 const command = res.positionals[0] orelse return error.MissingCommand;
56 switch (command) { 56 switch (command) {
57 .help => std.debug.print("--help\n", .{}), 57 .help => std.debug.print("--help\n", .{}),
58 .math => try mathMain(gpa, &iter, res), 58 .math => try mathMain(io, gpa, &iter, res),
59 } 59 }
60} 60}
61 61
62fn mathMain(gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: MainArgs) !void { 62fn mathMain(io: std.Io, gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: MainArgs) !void {
63 // The parent arguments are not used here, but there are cases where it might be useful, so 63 // The parent arguments are not used here, but there are cases where it might be useful, so
64 // this example shows how to pass the arguments around. 64 // this example shows how to pass the arguments around.
65 _ = main_args; 65 _ = main_args;
@@ -76,8 +76,6 @@ fn mathMain(gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: M
76 76
77 // Here we pass the partially parsed argument iterator. 77 // Here we pass the partially parsed argument iterator.
78 var diag = clap.Diagnostic{}; 78 var diag = clap.Diagnostic{};
79 var threaded: std.Io.Threaded = .init_single_threaded;
80 const io: std.Io = threaded.io();
81 var res = clap.parseEx(clap.Help, &params, clap.parsers.default, iter, .{ 79 var res = clap.parseEx(clap.Help, &params, clap.parsers.default, iter, .{
82 .diagnostic = &diag, 80 .diagnostic = &diag,
83 .allocator = gpa, 81 .allocator = gpa,