noclip: support --long=value style long options as well
I think this is a very reasonable way to do this. Not much complexity.
This commit is contained in:
parent
261ae7af31
commit
af71064d7f
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user