Cleanup parsing of single char options
This commit is contained in:
parent
23d2293296
commit
db972f3442
@ -235,19 +235,26 @@ func parse_args(args ...string) (delegate_to_rg bool, sanitized_args []string, k
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if strings.HasPrefix(x, "-") {
|
} else if strings.HasPrefix(x, "-") {
|
||||||
sanitized_args = append(sanitized_args, x)
|
ok := true
|
||||||
for _, ch := range x[1 : len(x)-1] {
|
chars := make([]string, len(x)-1)
|
||||||
target := alias_map[string(ch)]
|
for i, ch := range x[1:] {
|
||||||
if target != "" {
|
chars[i] = string(ch)
|
||||||
handle_bool_option(target)
|
_, ok = alias_map[string(ch)]
|
||||||
|
if !ok {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
target := alias_map[string(rune(x[len(x)-1]))]
|
if !ok {
|
||||||
if target != "" {
|
sanitized_args = append(sanitized_args, x)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, ch := range chars {
|
||||||
|
target := alias_map[ch]
|
||||||
if options_that_expect_args[target] {
|
if options_that_expect_args[target] {
|
||||||
expecting_option_arg = target
|
expecting_option_arg = target
|
||||||
} else {
|
} else {
|
||||||
handle_bool_option(target)
|
handle_bool_option(target)
|
||||||
|
sanitized_args = append(sanitized_args, "-"+ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -86,5 +86,8 @@ func TestRgArgParsing(t *testing.T) {
|
|||||||
}
|
}
|
||||||
check_args("--count --max-depth 10 --XxX yyy abcd", "--count --max-depth 10 --XxX yyy abcd")
|
check_args("--count --max-depth 10 --XxX yyy abcd", "--count --max-depth 10 --XxX yyy abcd")
|
||||||
check_args("--max-depth=10 --kitten hyperlink=none abcd", "--max-depth=10 abcd")
|
check_args("--max-depth=10 --kitten hyperlink=none abcd", "--max-depth=10 abcd")
|
||||||
|
check_args("-m 10 abcd", "--max-count 10 abcd")
|
||||||
|
check_args("-nm 10 abcd", "-n --max-count 10 abcd")
|
||||||
|
check_args("-mn 10 abcd", "-n --max-count 10 abcd")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user