flags: further cleanup after Zig 0.10

Long live the self hosted compiler!
This commit is contained in:
Isaac Freund 2023-01-08 17:01:14 +01:00
parent 09f3f141ae
commit 2c0c606596
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
4 changed files with 6 additions and 13 deletions

View File

@ -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{

View File

@ -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);
};

View File

@ -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);
};

View File

@ -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);
};