From af71064d7f45db759b9a9ab59170f8ef9c86500d Mon Sep 17 00:00:00 2001 From: torque Date: Thu, 23 Mar 2023 00:47:34 -0700 Subject: [PATCH] noclip: support --long=value style long options as well I think this is a very reasonable way to do this. Not much complexity. --- source/noclip.zig | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/source/noclip.zig b/source/noclip.zig index ccea214..cbd212e 100644 --- a/source/noclip.zig +++ b/source/noclip.zig @@ -111,12 +111,16 @@ pub fn CommandParser( switch (@TypeOf(param).brand) { .Option => { if (param.long) |flag| { - if (std.mem.eql(u8, flag, arg)) { + if (std.mem.startsWith(u8, arg, flag) and (flag.len == arg.len or arg[flag.len] == '=')) { + const val = if (flag.len == arg.len) + argit.next() orelse return OptionError.MissingArgument + else + arg[flag.len + 1 ..]; + if (comptime param.required()) { @field(required, param.name) = true; } - const val = argit.next() orelse return OptionError.MissingArgument; if (param.hideResult == false) { @field(result, param.name) = try param.handler.?(context, val); }