@@ -28,6 +28,10 @@ import (
2828 "github.com/apache/cloudstack-cloudmonkey/config"
2929)
3030
31+ var nameSupportingApis = []string {
32+ "configuration" ,
33+ }
34+
3135func buildAPICacheMap (apiMap map [string ][]* config.API ) map [string ][]* config.API {
3236 for _ , cmd := range cmd .AllCommands () {
3337 verb := cmd .Name
@@ -232,14 +236,25 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st
232236 default :
233237 // Heuristic: autocomplete for the arg for which a list<Arg without id/ids>s API exists
234238 // For example, for zoneid arg, listZones API exists
235- cutIdx := len ( argName )
239+ base := argName
236240 if strings .HasSuffix (argName , "id" ) {
237- cutIdx -= 2
241+ base = strings . TrimSuffix ( argName , "id" )
238242 } else if strings .HasSuffix (argName , "ids" ) {
239- cutIdx -= 3
243+ base = strings .TrimSuffix (argName , "ids" )
244+ } else if argName == "name" {
245+ for _ , noun := range nameSupportingApis {
246+ if strings .HasPrefix (apiFound .Noun , noun ) {
247+ base = noun
248+ break
249+ }
250+ }
251+ }
252+ // Handle common cases where base ends with a vowel and needs "es"
253+ if strings .HasSuffix (base , "s" ) || strings .HasSuffix (base , "x" ) || strings .HasSuffix (base , "z" ) || strings .HasSuffix (base , "ch" ) || strings .HasSuffix (base , "sh" ) {
254+ relatedNoun = base + "es"
240255 } else {
256+ relatedNoun = base + "s"
241257 }
242- relatedNoun = argName [:cutIdx ] + "s"
243258 }
244259
245260 config .Debug ("Possible related noun for the arg: " , relatedNoun , " and type: " , arg .Type )
0 commit comments