From 2c541a7e86df205d02374a07f4b10a4c0ca83f14 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 27 Oct 2023 18:26:44 -0700 Subject: [PATCH] config: -e replaces previous args --- src/config/Config.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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;