diff --git a/src/config/Config.zig b/src/config/Config.zig index b391a1076..453913937 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1167,6 +1167,7 @@ pub fn parseManuallyHook(self: *Config, alloc: Allocator, arg: []const u8, iter: } // All further arguments are parameters + self.@"command-arg".list.clearRetainingCapacity(); while (iter.next()) |param| { try self.@"command-arg".parseCLI(alloc, param); } @@ -1356,6 +1357,21 @@ test "parse e: command and args" { try testing.expectEqualStrings("bar baz", cfg.@"command-arg".list.items[1]); } +test "parse e: command replaces args" { + const testing = std.testing; + var cfg = try Config.default(testing.allocator); + defer cfg.deinit(); + const alloc = cfg._arena.?.allocator(); + + try cfg.@"command-arg".parseCLI(alloc, "foo"); + try testing.expectEqual(@as(usize, 1), cfg.@"command-arg".list.items.len); + + var it: TestIterator = .{ .data = &.{"echo"} }; + try testing.expect(!try cfg.parseManuallyHook(alloc, "-e", &it)); + try testing.expectEqualStrings("echo", cfg.command.?); + try testing.expectEqual(@as(usize, 0), cfg.@"command-arg".list.items.len); +} + test "clone default" { const testing = std.testing; const alloc = testing.allocator;