~novakane/zelbar

1226c99f053770f8b73bcaa9e89f58349016ef6d — Hugo Machet 1 year, 3 months ago 69d8430
common/flags: Update to latest upstream
1 files changed, 11 insertions(+), 2 deletions(-)

M common/flags.zig
M common/flags.zig => common/flags.zig +11 -2
@@ 70,8 70,13 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {

            var i: usize = 0;
            outer: while (i < args.len) : (i += 1) {
                const arg = switch (Arg) {
                    [*:0]const u8 => mem.sliceTo(args[i], 0),
                    [:0]const u8 => args[i],
                    else => unreachable,
                };
                inline for (flags) |flag| {
                    if (mem.eql(u8, "-" ++ flag.name, mem.span(args[i]))) {
                    if (mem.eql(u8, "-" ++ flag.name, arg)) {
                        switch (flag.kind) {
                            .boolean => @field(result_flags, flag.name) = true,
                            .arg => {


@@ 81,7 86,11 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {
                                        "' requires an argument but none was provided!", .{});
                                    return error.MissingFlagArgument;
                                }
                                @field(result_flags, flag.name) = mem.span(args[i]);
                                @field(result_flags, flag.name) = switch (Arg) {
                                    [*:0]const u8 => mem.sliceTo(args[i], 0),
                                    [:0]const u8 => args[i],
                                    else => unreachable,
                                };
                            },
                        }
                        continue :outer;