diff --git a/tools/cmd/hyperlinked_grep/main.go b/tools/cmd/hyperlinked_grep/main.go index e35a13db5..d57a6a856 100644 --- a/tools/cmd/hyperlinked_grep/main.go +++ b/tools/cmd/hyperlinked_grep/main.go @@ -119,7 +119,7 @@ func parse_args(args ...string) (delegate_to_rg bool, sanitized_args []string, k if with_equals { sanitized_args = append(sanitized_args, "--"+key+"="+val) } else { - sanitized_args = append(sanitized_args, key, val) + sanitized_args = append(sanitized_args, "--"+key, val) } } switch key { diff --git a/tools/cmd/hyperlinked_grep/main_test.go b/tools/cmd/hyperlinked_grep/main_test.go index 71e334ee7..a6d8413c7 100644 --- a/tools/cmd/hyperlinked_grep/main_test.go +++ b/tools/cmd/hyperlinked_grep/main_test.go @@ -4,7 +4,10 @@ package hyperlinked_grep import ( "fmt" + "kitty/tools/utils/shlex" "testing" + + "github.com/google/go-cmp/cmp" ) var _ = fmt.Print @@ -64,4 +67,24 @@ func TestRgArgParsing(t *testing.T) { check_kitten_opts(true, true, true, "--no-heading", "--pretty") check_kitten_opts(true, true, true, "--no-heading", "--heading") + check_args := func(args, expected string) { + a, err := shlex.Split(args) + if err != nil { + t.Fatal(err) + } + _, actual, _, err := parse_args(a...) + if err != nil { + t.Fatalf("error when parsing: %#v: %s", args, err) + } + ex, err := shlex.Split(expected) + if err != nil { + t.Fatal(err) + } + if diff := cmp.Diff(ex, actual); diff != "" { + t.Fatalf("args not correct for %s\n%s", args, diff) + } + } + 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") + }