From a5dbe1ad280017ab390fe53d653f940eb4b319bc Mon Sep 17 00:00:00 2001 From: Pearl Dsilva Date: Tue, 2 Sep 2025 15:01:51 -0400 Subject: [PATCH 1/3] Fix auto-completion logic for APIs that end with 'y' --- cli/completer.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cli/completer.go b/cli/completer.go index 755cc7f..ebe8c0a 100644 --- a/cli/completer.go +++ b/cli/completer.go @@ -221,7 +221,13 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st // Heuristic: user is trying to autocomplete for id/ids arg for a list API relatedNoun = apiFound.Noun if apiFound.Verb != "list" { - relatedNoun += "s" + config.Debug("relatedNoun before suffix check: ", relatedNoun) + if strings.HasSuffix(relatedNoun, "y") && len(relatedNoun) > 1 && !strings.ContainsAny(string(relatedNoun[len(relatedNoun)-2]), "aeiou") { + // Handle words ending in consonant + y (e.g., policy -> policies) + relatedNoun = relatedNoun[:len(relatedNoun)-1] + "ies" + } else if !strings.HasSuffix(relatedNoun, "ies") { + relatedNoun += "s" + } } case argName == "account": // Heuristic: user is trying to autocomplete for accounts From f18def8a09df18f08a617957c4d7db1b64312172 Mon Sep 17 00:00:00 2001 From: Pearl1594 Date: Fri, 21 Aug 2026 09:52:54 -0400 Subject: [PATCH 2/3] xtract shared pluralizeNoun helper for autocomplete heuristics --- cli/completer.go | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/cli/completer.go b/cli/completer.go index ebe8c0a..73a179f 100644 --- a/cli/completer.go +++ b/cli/completer.go @@ -208,6 +208,22 @@ func findAPI(apiMap map[string][]*config.API, relatedNoun string) *config.API { return autocompleteAPI } +// pluralizeNoun applies simple English pluralization rules used by the +// autocomplete heuristics below (e.g., policy -> policies, disk -> disks). +func pluralizeNoun(noun string) string { + switch { + case strings.HasSuffix(noun, "ies"): + return noun + case strings.HasSuffix(noun, "y") && len(noun) > 1 && !strings.ContainsAny(string(noun[len(noun)-2]), "aeiou"): + // Handle words ending in consonant + y (e.g., policy -> policies) + return noun[:len(noun)-1] + "ies" + case strings.HasSuffix(noun, "s") || strings.HasSuffix(noun, "x") || strings.HasSuffix(noun, "z") || strings.HasSuffix(noun, "ch") || strings.HasSuffix(noun, "sh"): + return noun + "es" + default: + return noun + "s" + } +} + func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[string][]*config.API) *config.API { if arg.Type == "map" { return nil @@ -221,13 +237,7 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st // Heuristic: user is trying to autocomplete for id/ids arg for a list API relatedNoun = apiFound.Noun if apiFound.Verb != "list" { - config.Debug("relatedNoun before suffix check: ", relatedNoun) - if strings.HasSuffix(relatedNoun, "y") && len(relatedNoun) > 1 && !strings.ContainsAny(string(relatedNoun[len(relatedNoun)-2]), "aeiou") { - // Handle words ending in consonant + y (e.g., policy -> policies) - relatedNoun = relatedNoun[:len(relatedNoun)-1] + "ies" - } else if !strings.HasSuffix(relatedNoun, "ies") { - relatedNoun += "s" - } + relatedNoun = pluralizeNoun(relatedNoun) } case argName == "account": // Heuristic: user is trying to autocomplete for accounts @@ -255,12 +265,7 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st } } } - // Handle common cases where base ends with a vowel and needs "es" - if strings.HasSuffix(base, "s") || strings.HasSuffix(base, "x") || strings.HasSuffix(base, "z") || strings.HasSuffix(base, "ch") || strings.HasSuffix(base, "sh") { - relatedNoun = base + "es" - } else { - relatedNoun = base + "s" - } + relatedNoun = pluralizeNoun(base) } config.Debug("Possible related noun for the arg: ", relatedNoun, " and type: ", arg.Type) From 07b129f85a42ce554ad42c62443eeb5e42e25234 Mon Sep 17 00:00:00 2001 From: Pearl1594 Date: Fri, 21 Aug 2026 10:12:11 -0400 Subject: [PATCH 3/3] omit already plural apis --- cli/completer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/completer.go b/cli/completer.go index 73a179f..6db3d30 100644 --- a/cli/completer.go +++ b/cli/completer.go @@ -236,7 +236,8 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st case argName == "id" || argName == "ids": // Heuristic: user is trying to autocomplete for id/ids arg for a list API relatedNoun = apiFound.Noun - if apiFound.Verb != "list" { + if apiFound.Verb != "list" && findAPI(apiMap, relatedNoun) == nil { + // Noun may already be plural (e.g. bulk ops like deleteAlerts) relatedNoun = pluralizeNoun(relatedNoun) } case argName == "account":