From 8dd8bae0cd0b50ab9a9071b3adabe25b512250d1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 3 Jan 2024 09:35:03 -0800 Subject: [PATCH] config: empty value for RepeatableString resets the list --- src/config/Config.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/config/Config.zig b/src/config/Config.zig index 154e010a4..5d53c6c45 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -2213,6 +2213,13 @@ pub const RepeatableString = struct { pub fn parseCLI(self: *Self, alloc: Allocator, input: ?[]const u8) !void { const value = input orelse return error.ValueRequired; + + // Empty value resets the list + if (value.len == 0) { + self.list.clearRetainingCapacity(); + return; + } + const copy = try alloc.dupeZ(u8, value); try self.list.append(alloc, copy); } @@ -2248,8 +2255,10 @@ pub const RepeatableString = struct { var list: Self = .{}; try list.parseCLI(alloc, "A"); try list.parseCLI(alloc, "B"); - try testing.expectEqual(@as(usize, 2), list.list.items.len); + + try list.parseCLI(alloc, ""); + try testing.expectEqual(@as(usize, 0), list.list.items.len); } };