From 2c0c60659625b135c4377b3d4766f7a2e3825c9a Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Sun, 8 Jan 2023 17:01:14 +0100 Subject: [PATCH] flags: further cleanup after Zig 0.10 Long live the self hosted compiler! --- common/flags.zig | 7 +++---- river/main.zig | 4 +--- riverctl/main.zig | 4 +--- rivertile/main.zig | 4 +--- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/common/flags.zig b/common/flags.zig index cde7cad..1e34ce1 100644 --- a/common/flags.zig +++ b/common/flags.zig @@ -69,8 +69,7 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type { var result_flags: Result.Flags = .{}; var i: usize = 0; - while (i < args.len) : (i += 1) { - var parsed_flag = false; + outer: while (i < args.len) : (i += 1) { inline for (flags) |flag| { if (mem.eql(u8, "-" ++ flag.name, mem.span(args[i]))) { switch (flag.kind) { @@ -85,10 +84,10 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type { @field(result_flags, flag.name) = mem.span(args[i]); }, } - parsed_flag = true; + continue :outer; } } - if (!parsed_flag) break; + break; } return Result{ diff --git a/river/main.zig b/river/main.zig index ac7be9c..c030a8e 100644 --- a/river/main.zig +++ b/river/main.zig @@ -42,14 +42,12 @@ const usage: []const u8 = pub var server: Server = undefined; pub fn main() anyerror!void { - // This line is here because of https://github.com/ziglang/zig/issues/7807 - const argv: [][*:0]const u8 = os.argv; const result = flags.parser([*:0]const u8, &.{ .{ .name = "h", .kind = .boolean }, .{ .name = "version", .kind = .boolean }, .{ .name = "c", .kind = .arg }, .{ .name = "log-level", .kind = .arg }, - }).parse(argv[1..]) catch { + }).parse(os.argv[1..]) catch { try io.getStdErr().writeAll(usage); os.exit(1); }; diff --git a/riverctl/main.zig b/riverctl/main.zig index bffd20e..b3861c3 100644 --- a/riverctl/main.zig +++ b/riverctl/main.zig @@ -63,12 +63,10 @@ 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.parser([*:0]const u8, &.{ .{ .name = "h", .kind = .boolean }, .{ .name = "version", .kind = .boolean }, - }).parse(argv[1..]) catch { + }).parse(os.argv[1..]) catch { try io.getStdErr().writeAll(usage); os.exit(1); }; diff --git a/rivertile/main.zig b/rivertile/main.zig index 293ffeb..6b9c458 100644 --- a/rivertile/main.zig +++ b/rivertile/main.zig @@ -303,8 +303,6 @@ const Output = struct { }; pub fn main() !void { - // https://github.com/ziglang/zig/issues/7807 - const argv: [][*:0]const u8 = os.argv; const result = flags.parser([*:0]const u8, &[_]flags.Flag{ .{ .name = "h", .kind = .boolean }, .{ .name = "version", .kind = .boolean }, @@ -313,7 +311,7 @@ pub fn main() !void { .{ .name = "main-location", .kind = .arg }, .{ .name = "main-count", .kind = .arg }, .{ .name = "main-ratio", .kind = .arg }, - }).parse(argv[1..]) catch { + }).parse(os.argv[1..]) catch { try std.io.getStdErr().writeAll(usage); os.exit(1); };