Skip to content

Commit e309c00

Browse files
dheeraj12347borisstoyanov
authored andcommitted
feat: use Related metadata for autocomplete API discovery
1 parent c3c3377 commit e309c00

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎cli/completer.go‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,33 @@ func findAutocompleteAPI(arg *config.APIArg, apiFound *config.API, apiMap map[st
269269
relatedNoun = pluralizeNoun(base)
270270
}
271271

272+
// Prefer authoritative Related metadata: a list API whose noun matches
273+
// the related noun derived above.
274+
for _, relatedAPI := range arg.Related {
275+
if !strings.HasPrefix(strings.ToLower(relatedAPI), "list") {
276+
continue
277+
}
278+
for _, listAPI := range apiMap["list"] {
279+
if strings.EqualFold(listAPI.Name, relatedAPI) && strings.EqualFold(listAPI.Noun, relatedNoun) {
280+
config.Debug("Autocomplete: API found using Related metadata: ", listAPI.Name)
281+
return listAPI
282+
}
283+
}
284+
}
285+
286+
// Fall back to any list API named in the Related metadata.
287+
for _, relatedAPI := range arg.Related {
288+
if !strings.HasPrefix(strings.ToLower(relatedAPI), "list") {
289+
continue
290+
}
291+
for _, listAPI := range apiMap["list"] {
292+
if strings.EqualFold(listAPI.Name, relatedAPI) {
293+
config.Debug("Autocomplete: API found using Related metadata fallback: ", listAPI.Name)
294+
return listAPI
295+
}
296+
}
297+
}
298+
272299
config.Debug("Possible related noun for the arg: ", relatedNoun, " and type: ", arg.Type)
273300
autocompleteAPI = findAPI(apiMap, relatedNoun)
274301

0 commit comments

Comments
 (0)