From e73b56aa4bcb7e53144ef96ee978f2a19b32669d Mon Sep 17 00:00:00 2001 From: Jimmi Holst Christensen Date: Tue, 22 Oct 2024 17:46:47 +0200 Subject: refactor: Always access using full namespace This is my new preferred style of programming Zig :) --- example/streaming-clap.zig | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'example/streaming-clap.zig') diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index 9d99859..2a20bcb 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig @@ -1,10 +1,3 @@ -const clap = @import("clap"); -const std = @import("std"); - -const debug = std.debug; -const io = std.io; -const process = std.process; - pub fn main() !void { const allocator = std.heap.page_allocator; @@ -22,7 +15,7 @@ pub fn main() !void { .{ .id = 'f', .takes_value = .one }, }; - var iter = try process.ArgIterator.initWithAllocator(allocator); + var iter = try std.process.ArgIterator.initWithAllocator(allocator); defer iter.deinit(); // Skip exe argument @@ -32,7 +25,7 @@ pub fn main() !void { // This is optional. You can also leave the `diagnostic` field unset if you // don't care about the extra information `Diagnostic` provides. var diag = clap.Diagnostic{}; - var parser = clap.streaming.Clap(u8, process.ArgIterator){ + var parser = clap.streaming.Clap(u8, std.process.ArgIterator){ .params = ¶ms, .iter = &iter, .diagnostic = &diag, @@ -41,19 +34,22 @@ pub fn main() !void { // Because we use a streaming parser, we have to consume each argument parsed individually. while (parser.next() catch |err| { // Report useful error and exit - diag.report(io.getStdErr().writer(), err) catch {}; + diag.report(std.io.getStdErr().writer(), err) catch {}; return err; }) |arg| { // arg.param will point to the parameter which matched the argument. switch (arg.param.id) { - 'h' => debug.print("Help!\n", .{}), - 'n' => debug.print("--number = {s}\n", .{arg.value.?}), + 'h' => std.debug.print("Help!\n", .{}), + 'n' => std.debug.print("--number = {s}\n", .{arg.value.?}), // arg.value == null, if arg.param.takes_value == .none. // Otherwise, arg.value is the value passed with the argument, such as "-a=10" // or "-a 10". - 'f' => debug.print("{s}\n", .{arg.value.?}), + 'f' => std.debug.print("{s}\n", .{arg.value.?}), else => unreachable, } } } + +const clap = @import("clap"); +const std = @import("std"); -- cgit v1.2.3