improve args handling

main 0.1.1
moss 2025-01-25 18:15:36 -06:00
parent c88a2815fa
commit 12e96454ff
1 changed files with 9 additions and 2 deletions

View File

@ -9,7 +9,8 @@ pub fn main() !void {
const params = comptime clap.parseParamsComptime( const params = comptime clap.parseParamsComptime(
\\-h, --help display this help and exit \\-h, --help display this help and exit
\\<FILE> file to read from, if empty or "-" use stdin. \\-v, --version display the version and exit
\\<FILE> file to read from, empty or "-" use stdin
\\ \\
); );
@ -27,8 +28,14 @@ pub fn main() !void {
}; };
defer res.deinit(); defer res.deinit();
if (res.args.help != 0) return clap.help(std.io.getStdErr().writer(), clap.Help, &params, .{});
const version_string = "0.1.1\n";
if (res.args.version != 0) return std.debug.print(version_string, .{});
var reader: std.io.AnyReader = undefined; 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(); reader = std.io.getStdIn().reader().any();
} else { } else {
const filename = res.positionals[0]; const filename = res.positionals[0];