@@ -185,6 +185,17 @@ func doInternal(line []rune, pos int, lineLen int, argName []rune) (newLine [][]
185
185
return
186
186
}
187
187
188
+ func findAPI (apiMap map [string ][]* config.API , relatedNoun string ) * config.API {
189
+ var autocompleteAPI * config.API
190
+ for _ , listAPI := range apiMap ["list" ] {
191
+ if relatedNoun == listAPI .Noun {
192
+ autocompleteAPI = listAPI
193
+ break
194
+ }
195
+ }
196
+ return autocompleteAPI
197
+ }
198
+
188
199
func findAutocompleteAPI (arg * config.APIArg , apiFound * config.API , apiMap map [string ][]* config.API ) * config.API {
189
200
if arg .Type == "map" {
190
201
return nil
@@ -193,19 +204,22 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st
193
204
var autocompleteAPI * config.API
194
205
argName := strings .Replace (arg .Name , "=" , "" , - 1 )
195
206
relatedNoun := argName
196
- if argName == "id" || argName == "ids" {
207
+ switch {
208
+ case argName == "id" || argName == "ids" :
197
209
// Heuristic: user is trying to autocomplete for id/ids arg for a list API
198
210
relatedNoun = apiFound .Noun
199
211
if apiFound .Verb != "list" {
200
212
relatedNoun += "s"
201
213
}
202
- } else if argName == "account" {
214
+ case argName == "account" :
203
215
// Heuristic: user is trying to autocomplete for accounts
204
216
relatedNoun = "accounts"
205
- } else if argName == "ipaddressid" {
217
+ case argName == "ipaddressid" :
206
218
// Heuristic: user is trying to autocomplete for ip addresses
207
219
relatedNoun = "publicipaddresses"
208
- } else {
220
+ case argName == "storageid" :
221
+ relatedNoun = "storagepools"
222
+ default :
209
223
// Heuristic: autocomplete for the arg for which a list<Arg without id/ids>s API exists
210
224
// For example, for zoneid arg, listZones API exists
211
225
cutIdx := len (argName )
@@ -219,10 +233,12 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st
219
233
}
220
234
221
235
config .Debug ("Possible related noun for the arg: " , relatedNoun , " and type: " , arg .Type )
222
- for _ , listAPI := range apiMap ["list" ] {
223
- if relatedNoun == listAPI .Noun {
224
- autocompleteAPI = listAPI
225
- break
236
+ autocompleteAPI = findAPI (apiMap , relatedNoun )
237
+
238
+ if autocompleteAPI == nil {
239
+ if strings .Contains (strings .ToLower (relatedNoun ), "storage" ) {
240
+ relatedNoun = "storagepools"
241
+ autocompleteAPI = findAPI (apiMap , relatedNoun )
226
242
}
227
243
}
228
244
0 commit comments