Skip to content

Commit 19d41df

Browse files
authored
Support for auto-completion of storage pool related APIs (#111)
1 parent e21ad84 commit 19d41df

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

cli/completer.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ func doInternal(line []rune, pos int, lineLen int, argName []rune) (newLine [][]
185185
return
186186
}
187187

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+
188199
func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[string][]*config.API) *config.API {
189200
if arg.Type == "map" {
190201
return nil
@@ -193,19 +204,22 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st
193204
var autocompleteAPI *config.API
194205
argName := strings.Replace(arg.Name, "=", "", -1)
195206
relatedNoun := argName
196-
if argName == "id" || argName == "ids" {
207+
switch {
208+
case argName == "id" || argName == "ids":
197209
// Heuristic: user is trying to autocomplete for id/ids arg for a list API
198210
relatedNoun = apiFound.Noun
199211
if apiFound.Verb != "list" {
200212
relatedNoun += "s"
201213
}
202-
} else if argName == "account" {
214+
case argName == "account":
203215
// Heuristic: user is trying to autocomplete for accounts
204216
relatedNoun = "accounts"
205-
} else if argName == "ipaddressid" {
217+
case argName == "ipaddressid":
206218
// Heuristic: user is trying to autocomplete for ip addresses
207219
relatedNoun = "publicipaddresses"
208-
} else {
220+
case argName == "storageid":
221+
relatedNoun = "storagepools"
222+
default:
209223
// Heuristic: autocomplete for the arg for which a list<Arg without id/ids>s API exists
210224
// For example, for zoneid arg, listZones API exists
211225
cutIdx := len(argName)
@@ -219,10 +233,12 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st
219233
}
220234

221235
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)
226242
}
227243
}
228244

0 commit comments

Comments
 (0)