config: -e replaces previous args

This commit is contained in:
Mitchell Hashimoto
2023-10-27 18:26:44 -07:00
parent 4f62526782
commit 2c541a7e86

View File

@ -1167,6 +1167,7 @@ pub fn parseManuallyHook(self: *Config, alloc: Allocator, arg: []const u8, iter:
} }
// All further arguments are parameters // All further arguments are parameters
self.@"command-arg".list.clearRetainingCapacity();
while (iter.next()) |param| { while (iter.next()) |param| {
try self.@"command-arg".parseCLI(alloc, 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]); 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" { test "clone default" {
const testing = std.testing; const testing = std.testing;
const alloc = testing.allocator; const alloc = testing.allocator;