From 1d3d273524e3c180f015ff1e93c83075e4634e2c Mon Sep 17 00:00:00 2001 From: darcy Date: Sun, 25 Jan 2026 09:27:04 +1100 Subject: fix: use new `std.process.Init` args for Zig `0.16.0-dev.2261+d6b3dd25a` (#175) --- example/subcommands.zig | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'example/subcommands.zig') diff --git a/example/subcommands.zig b/example/subcommands.zig index bd8625b..0b14efe 100644 --- a/example/subcommands.zig +++ b/example/subcommands.zig @@ -19,15 +19,8 @@ const main_params = clap.parseParamsComptime( // get the return type of `clap.parse` and `clap.parseEx`. const MainArgs = clap.ResultEx(clap.Help, &main_params, main_parsers); -pub fn main() !void { - var gpa_state = std.heap.DebugAllocator(.{}){}; - const gpa = gpa_state.allocator(); - defer _ = gpa_state.deinit(); - - var threaded: std.Io.Threaded = .init_single_threaded; - const io: std.Io = threaded.io(); - - var iter = try std.process.ArgIterator.initWithAllocator(gpa); +pub fn main(init: std.process.Init) !void { + var iter = try init.minimal.args.iterateAllocator(init.gpa); defer iter.deinit(); _ = iter.next(); @@ -35,7 +28,7 @@ pub fn main() !void { var diag = clap.Diagnostic{}; var res = clap.parseEx(clap.Help, &main_params, main_parsers, &iter, .{ .diagnostic = &diag, - .allocator = gpa, + .allocator = init.gpa, // Terminate the parsing of arguments after parsing the first positional (0 is passed // here because parsed positionals are, like slices and arrays, indexed starting at 0). @@ -44,7 +37,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(io, .stderr(), err); + try diag.reportToFile(init.io, .stderr(), err); return err; }; defer res.deinit(); @@ -55,11 +48,11 @@ pub fn main() !void { const command = res.positionals[0] orelse return error.MissingCommand; switch (command) { .help => std.debug.print("--help\n", .{}), - .math => try mathMain(io, gpa, &iter, res), + .math => try mathMain(init.io, init.gpa, &iter, res), } } -fn mathMain(io: std.Io, gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: MainArgs) !void { +fn mathMain(io: std.Io, gpa: std.mem.Allocator, iter: *std.process.Args.Iterator, main_args: MainArgs) !void { // The parent arguments are not used here, but there are cases where it might be useful, so // this example shows how to pass the arguments around. _ = main_args; -- cgit v1.2.3