This is an automated email from the ASF dual-hosted git repository.

shwstppr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack-cloudmonkey.git


The following commit(s) were added to refs/heads/main by this push:
     new 94c1ef7  autocomplete: allow searching configuration name (#184)
94c1ef7 is described below

commit 94c1ef760e5c95bcd7fa4a76975029985537513a
Author: Abhishek Kumar <[email protected]>
AuthorDate: Mon Aug 25 14:32:28 2025 +0530

    autocomplete: allow searching configuration name (#184)
    
    Allows searching name for configurations for all *configuration(s) APIs.
    
    ---------
    
    Signed-off-by: Abhishek Kumar <[email protected]>
---
 cli/completer.go | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/cli/completer.go b/cli/completer.go
index e23d187..986b7e9 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
@@ -232,14 +236,25 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound 
*config.API, apiMap map[st
        default:
                // Heuristic: autocomplete for the arg for which a list<Arg 
without id/ids>s 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" {
+                       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") {
+                       relatedNoun = base + "es"
                } else {
+                       relatedNoun = base + "s"
                }
-               relatedNoun = argName[:cutIdx] + "s"
        }
 
        config.Debug("Possible related noun for the arg: ", relatedNoun, " and 
type: ", arg.Type)

Reply via email to