From 12e96454ff6e883710cbc43c713673349300649f Mon Sep 17 00:00:00 2001 From: moss Date: Sat, 25 Jan 2025 18:15:36 -0600 Subject: [PATCH] improve args handling --- src/main.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index a02a902..48b2b16 100644 --- a/src/main.zig +++ b/src/main.zig @@ -9,7 +9,8 @@ pub fn main() !void { const params = comptime clap.parseParamsComptime( \\-h, --help display this help and exit - \\ file to read from, if empty or "-" use stdin. + \\-v, --version display the version and exit + \\ file to read from, empty or "-" use stdin \\ ); @@ -27,8 +28,14 @@ pub fn main() !void { }; defer res.deinit(); + if (res.args.help != 0) return clap.help(std.io.getStdErr().writer(), clap.Help, ¶ms, .{}); + + const version_string = "0.1.1\n"; + + if (res.args.version != 0) return std.debug.print(version_string, .{}); + var reader: std.io.AnyReader = undefined; - if (res.positionals.len < 1) { + if (res.positionals.len < 1 or std.mem.eql(u8, res.positionals[0], "-")) { reader = std.io.getStdIn().reader().any(); } else { const filename = res.positionals[0];