From bd7f38eb7d5abce9e3bac1559abb7708278abe6c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 27 Nov 2023 22:08:03 +0530 Subject: [PATCH] rg changed its help output to conform more closely to GNU conventions Which is good I suppose, but it breaks hyperlinked_greps --help parsing. I have updated it to match current rg which of course means it fails on older rg. --- kittens/hyperlinked_grep/main.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kittens/hyperlinked_grep/main.go b/kittens/hyperlinked_grep/main.go index b4adb5f97..f8a4e5ded 100644 --- a/kittens/hyperlinked_grep/main.go +++ b/kittens/hyperlinked_grep/main.go @@ -43,16 +43,18 @@ func get_options_for_rg() (expecting_args map[string]bool, alias_map map[string] if options_started { s := strings.TrimLeft(line, " ") indent := len(line) - len(s) - if indent < 12 && indent > 0 { - s, _, expecting_arg := strings.Cut(s, "<") + if indent < 8 && indent > 0 { + expecting_arg := strings.Contains(s, "=") single_letter_aliases := make([]string, 0, 1) long_option_names := make([]string, 0, 1) for _, x := range strings.Split(s, ",") { x = strings.TrimSpace(x) if strings.HasPrefix(x, "--") { - long_option_names = append(long_option_names, x[2:]) + lon, _, _ := strings.Cut(x[2:], "=") + long_option_names = append(long_option_names, lon) } else if strings.HasPrefix(x, "-") { - single_letter_aliases = append(single_letter_aliases, x[1:]) + son, _, _ := strings.Cut(x[1:], " ") + single_letter_aliases = append(single_letter_aliases, son) } } if len(long_option_names) == 0 { @@ -68,11 +70,15 @@ func get_options_for_rg() (expecting_args map[string]bool, alias_map map[string] expecting_args[long_option_names[0]] = expecting_arg } } else { - if strings.HasPrefix(line, "OPTIONS:") { + if strings.HasSuffix(line, "OPTIONS:") { options_started = true } } } + if len(expecting_args) == 0 || len(alias_map) == 0 { + err = fmt.Errorf("Failed to parse rg help output, could not find any options") + return + } return }