From 1f24c662b9e678b2ce34d226b97017ab68c14924 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 22 Aug 2025 16:22:50 +0530 Subject: [PATCH 1/2] autocomplete: allow searching configuration name Signed-off-by: Abhishek Kumar --- cli/completer.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cli/completer.go b/cli/completer.go index 7bc9e5a..3a23498 100644 --- a/cli/completer.go +++ b/cli/completer.go @@ -232,14 +232,20 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st default: // Heuristic: autocomplete for the arg for which a lists API exists // For example, for zoneid arg, listZones API exists - cutIdx := len(argName) + base := argName if strings.HasSuffix(argName, "id") { - cutIdx -= 2 + base = strings.TrimSuffix(argName, "id") } else if strings.HasSuffix(argName, "ids") { - cutIdx -= 3 + base = strings.TrimSuffix(argName, "ids") + } else if argName == "name" && strings.HasPrefix(apiFound.Noun, "configuration") { + base = "configuration" + } + // 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 = argName[:cutIdx] + "s" } config.Debug("Possible related noun for the arg: ", relatedNoun, " and type: ", arg.Type) From 09e8b601fd774d2b450df368b9ffe062329a3ca6 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Fri, 22 Aug 2025 23:27:10 +0530 Subject: [PATCH 2/2] change Signed-off-by: Abhishek Kumar --- cli/completer.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cli/completer.go b/cli/completer.go index 3a23498..65fe13d 100644 --- a/cli/completer.go +++ b/cli/completer.go @@ -28,6 +28,10 @@ import ( "github.com/apache/cloudstack-cloudmonkey/config" ) +var nameSupportingApis = []string{ + "configuration", +} + func buildAPICacheMap(apiMap map[string][]*config.API) map[string][]*config.API { for _, cmd := range cmd.AllCommands() { verb := cmd.Name @@ -237,8 +241,13 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st base = strings.TrimSuffix(argName, "id") } else if strings.HasSuffix(argName, "ids") { base = strings.TrimSuffix(argName, "ids") - } else if argName == "name" && strings.HasPrefix(apiFound.Noun, "configuration") { - base = "configuration" + } else if argName == "name" { + for _, noun := range nameSupportingApis { + if strings.HasPrefix(apiFound.Noun, noun) { + base = noun + break + } + } } // 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") {