mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-09 13:01:38 -07:00
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:
@@ -90,6 +90,14 @@ parse_one_unix_arg :: proc(model: ^$T, parser: ^Parser, arg: string) -> (
|
||||
if strings.has_prefix(arg, "-") {
|
||||
// Allow `--` to function as `-`.
|
||||
arg = arg[1:]
|
||||
|
||||
if len(arg) == 0 {
|
||||
// `--`, and only `--`.
|
||||
// Everything from now on will be treated as an argument.
|
||||
future_args = max(int)
|
||||
current_flag = INTERNAL_VARIADIC_FLAG
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
flag: string
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user