Add -- parsing to UNIX-style core:flags

This will allow a user to indicate all arguments after `--` are parsed
into the variadic array.
This commit is contained in:
Feoramund
2024-06-14 23:59:01 -04:00
parent edb685f04b
commit c3acdeb310
2 changed files with 35 additions and 0 deletions
+27
View File
@@ -1028,6 +1028,33 @@ test_unix_positional_with_variadic :: proc(t: ^testing.T) {
testing.expect_value(t, len(s.v), 2)
}
@(test)
test_unix_double_dash_variadic :: proc(t: ^testing.T) {
S :: struct {
varg: [dynamic]string,
i: int,
}
s: S
args := [?]string { "-i", "3", "--", "hellope", "-i", "5" }
result := flags.parse(&s, args[:], .Unix)
defer {
delete(s.varg)
}
testing.expect_value(t, result, nil)
testing.expect_value(t, len(s.varg), 3)
testing.expect_value(t, s.i, 3)
if len(s.varg) != 3 {
return
}
testing.expect_value(t, s.varg[0], "hellope")
testing.expect_value(t, s.varg[1], "-i")
testing.expect_value(t, s.varg[2], "5")
}
// This test ensures there are no bad frees with cstrings.
@(test)
test_if_dynamic_cstrings_get_freed :: proc(t: ^testing.T) {