You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2018/10/25 06:10:54 UTC

[cloudstack-cloudmonkey] branch master updated: cli: implement heuristics based completer as a fallback

This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack-cloudmonkey.git


The following commit(s) were added to refs/heads/master by this push:
     new 01c1f1f  cli: implement heuristics based completer as a fallback
01c1f1f is described below

commit 01c1f1f1473fe51d71e7e77915c783b96c981b11
Author: Rohit Yadav <ro...@apache.org>
AuthorDate: Thu Oct 25 11:39:37 2018 +0530

    cli: implement heuristics based completer as a fallback
    
    This implements a API heuristics based options API arg completer based
    on the related API name for an arg, or if a list API exists whose name
    contains the arg name.
    
    Signed-off-by: Rohit Yadav <ro...@apache.org>
---
 cli/completer.go | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/cli/completer.go b/cli/completer.go
index 06bd29b..29c944f 100644
--- a/cli/completer.go
+++ b/cli/completer.go
@@ -18,7 +18,6 @@
 package cli
 
 import (
-	"fmt"
 	"sort"
 	"strings"
 
@@ -152,6 +151,22 @@ func completer(in prompt.Document) []prompt.Suggest {
 								break
 							}
 						}
+						if optionsAPI == nil {
+							if len(argFound.Related) > 0 {
+								apiCache := cfg.GetCache()
+								relatedAPIName := strings.ToLower(argFound.Related[0])
+								if apiCache[relatedAPIName] != nil {
+									optionsAPI = apiCache[relatedAPIName]
+								}
+							} else {
+								for _, related := range apiMap["list"] {
+									if strings.Contains(related.Noun, relatedNoun) {
+										optionsAPI = related
+										break
+									}
+								}
+							}
+						}
 						if optionsAPI != nil {
 							r := cmd.NewRequest(nil, cfg, nil)
 							optionsArgs := []string{"listall=true"}
@@ -160,7 +175,6 @@ func completer(in prompt.Document) []prompt.Suggest {
 							}
 
 							if cachedResponse == nil {
-								fmt.Println("")
 								spinner := cfg.StartSpinner("fetching options, please wait...")
 								cachedResponse, _ = cmd.NewAPIRequest(r, optionsAPI.Name, optionsArgs, false)
 								cfg.StopSpinner(spinner)
@@ -186,7 +200,7 @@ func completer(in prompt.Document) []prompt.Suggest {
 										} else if resource["username"] != nil {
 											opt.Description = resource["username"].(string)
 										}
-										if opt.Text == "" {
+										if argFound.Type == "string" {
 											opt.Text = opt.Description
 										}
 										s = append(s, opt)