heuristics based api param completion
Signed-off-by: Rohit Yadav <rohit@apache.org>
diff --git a/cli/completer.go b/cli/completer.go
index a62fad0..d2fbcd6 100644
--- a/cli/completer.go
+++ b/cli/completer.go
@@ -128,9 +128,6 @@
return
}
-// FIXME; use cached response
-var cachedResponse map[string]interface{}
-
func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int) {
apiMap := buildAPICacheMap(t.Config.GetAPIVerbMap())
@@ -229,14 +226,37 @@
} else {
relatedNoun = strings.Replace(strings.Replace(argName, "ids", "", -1), "id", "", -1) + "s"
}
- for _, related := range apiMap["list"] {
- if relatedNoun == related.Noun {
- autocompleteAPI = related
+
+ for _, listAPI := range apiMap["list"] {
+ if relatedNoun == listAPI.Noun {
+ autocompleteAPI = listAPI
break
}
}
if autocompleteAPI == nil {
+ relatedAPIName := ""
+ for _, name := range arg.Related {
+ if strings.HasPrefix(name, "list") {
+ if len(relatedAPIName) == 0 {
+ relatedAPIName = name
+ }
+ if len(name) < len(relatedAPIName) {
+ relatedAPIName = name
+ }
+ }
+ }
+ if len(relatedAPIName) > 0 {
+ for _, listAPI := range apiMap["list"] {
+ if relatedAPIName == listAPI.Name {
+ autocompleteAPI = listAPI
+ break
+ }
+ }
+ }
+ }
+
+ if autocompleteAPI == nil {
return nil, 0
}
@@ -274,7 +294,12 @@
if resource["displaytext"] != nil {
opt.Detail = resource["displaytext"].(string)
}
-
+ if len(opt.Detail) == 0 && resource["description"] != nil {
+ opt.Detail = resource["description"].(string)
+ }
+ if len(opt.Detail) == 0 && resource["ipaddress"] != nil {
+ opt.Detail = resource["ipaddress"].(string)
+ }
selectOptions = append(selectOptions, opt)
}
break
@@ -290,7 +315,11 @@
for _, item := range selectOptions {
var option string
if hasID {
- option = fmt.Sprintf("%v (%v)", item.ID, item.Name)
+ if len(item.Name) > 0 {
+ option = fmt.Sprintf("%v (%v)", item.ID, item.Name)
+ } else {
+ option = fmt.Sprintf("%v (%v)", item.ID, item.Detail)
+ }
} else {
if len(item.Detail) == 0 {
option = fmt.Sprintf("%v ", item.Name)
diff --git a/config/about.go b/config/about.go
index 40155f4..b14034d 100644
--- a/config/about.go
+++ b/config/about.go
@@ -26,7 +26,7 @@
// Version CLI
func (c *Config) Version() string {
- return "6.0.0-beta2"
+ return "6.0.0-beta3"
}
// PrintHeader prints startup message in CLI mode