From 16cbe5f469594439035da63e1f40d3fffe66d9a9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Wed, 28 Dec 2022 19:47:09 +0100 Subject: flags: rewrite to allow [:0]const u8 arguments This also cleans up the code by using @Type(), eliminating the need for the argFlag() and boolFlag() functions. Allowing [:0]const u8 arguments makes this parser useful for river-control commands as well. --- riverctl/main.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'riverctl/main.zig') diff --git a/riverctl/main.zig b/riverctl/main.zig index 853b94e..4cc6717 100644 --- a/riverctl/main.zig +++ b/riverctl/main.zig @@ -65,18 +65,18 @@ pub fn main() !void { fn _main() !void { // This line is here because of https://github.com/ziglang/zig/issues/7807 const argv: [][*:0]const u8 = os.argv; - const result = flags.parse(argv[1..], &[_]flags.Flag{ + const result = flags.parser([*:0]const u8, &.{ .{ .name = "-h", .kind = .boolean }, .{ .name = "-version", .kind = .boolean }, - }) catch { + }).parse(argv[1..]) catch { try io.getStdErr().writeAll(usage); os.exit(1); }; - if (result.boolFlag("-h")) { + if (result.flags.@"-h") { try io.getStdOut().writeAll(usage); os.exit(0); } - if (result.boolFlag("-version")) { + if (result.flags.@"-version") { try io.getStdOut().writeAll(@import("build_options").version ++ "\n"); os.exit(0); } -- cgit v1.2.3