common/flags: make argFlag() return a slice

We always pass the result of this to mem.span() currently, no need for
the code duplication.
This commit is contained in:
Isaac Freund
2021-12-15 17:09:45 +01:00
parent d93ee2c27e
commit c3370afa3d
3 changed files with 11 additions and 9 deletions

View File

@ -63,9 +63,11 @@ pub fn ParseResult(comptime flags: []const Flag) type {
unreachable; // Invalid flag_name
}
pub fn argFlag(self: Self, flag_name: [*:0]const u8) ?[*:0]const u8 {
pub fn argFlag(self: Self, flag_name: [*:0]const u8) ?[:0]const u8 {
for (self.flag_data) |flag_data| {
if (cstr.cmp(flag_data.name, flag_name) == 0) return flag_data.value.arg;
if (cstr.cmp(flag_data.name, flag_name) == 0) {
return std.mem.span(flag_data.value.arg);
}
}
unreachable; // Invalid flag_name
}