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 2021/08/09 10:48:02 UTC

[cloudstack-cloudmonkey] branch main updated: Make auto completion optional (#91)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new 3293b74  Make auto completion optional (#91)
3293b74 is described below

commit 3293b74bf05617e795cbb64b0e429a35a546ce85
Author: Pearl Dsilva <pe...@gmail.com>
AuthorDate: Mon Aug 9 16:17:56 2021 +0530

    Make auto completion optional (#91)
    
    * Make auto completion optional
    
    * default autocompletion to true in absense of config
---
 cli/completer.go | 31 ++++++++++++++++++-------------
 cmd/set.go       | 27 ++++++++++++++-------------
 config/config.go | 19 +++++++++++++------
 3 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/cli/completer.go b/cli/completer.go
index ce2b7e2..650c84b 100644
--- a/cli/completer.go
+++ b/cli/completer.go
@@ -355,22 +355,27 @@ func (t *autoCompleter) Do(line []rune, pos int) (options [][]rune, offset int)
 				return nil, 0
 			}
 
-			autocompleteAPIArgs := []string{"listall=true"}
-			if autocompleteAPI.Noun == "templates" {
-				autocompleteAPIArgs = append(autocompleteAPIArgs, "templatefilter=executable")
-			}
+			completeArgs := t.Config.Core.AutoComplete
+			autocompleteAPIArgs := []string{}
+			argOptions := []argOption{}
+			if completeArgs {
+				autocompleteAPIArgs = []string{"listall=true"}
+				if autocompleteAPI.Noun == "templates" {
+					autocompleteAPIArgs = append(autocompleteAPIArgs, "templatefilter=executable")
+				}
 
-			if apiFound.Name != "provisionCertificate" && autocompleteAPI.Name == "listHosts" {
-				autocompleteAPIArgs = append(autocompleteAPIArgs, "type=Routing")
-			}
+				if apiFound.Name != "provisionCertificate" && autocompleteAPI.Name == "listHosts" {
+					autocompleteAPIArgs = append(autocompleteAPIArgs, "type=Routing")
+				}
 
-			spinner := t.Config.StartSpinner("fetching options, please wait...")
-			request := cmd.NewRequest(nil, completer.Config, nil)
-			response, _ := cmd.NewAPIRequest(request, autocompleteAPI.Name, autocompleteAPIArgs, false)
-			t.Config.StopSpinner(spinner)
+				spinner := t.Config.StartSpinner("fetching options, please wait...")
+				request := cmd.NewRequest(nil, completer.Config, nil)
+				response, _ := cmd.NewAPIRequest(request, autocompleteAPI.Name, autocompleteAPIArgs, false)
+				t.Config.StopSpinner(spinner)
 
-			hasID := strings.HasSuffix(arg.Name, "id=") || strings.HasSuffix(arg.Name, "ids=")
-			argOptions := buildArgOptions(response, hasID)
+				hasID := strings.HasSuffix(arg.Name, "id=") || strings.HasSuffix(arg.Name, "ids=")
+				argOptions = buildArgOptions(response, hasID)
+			}
 
 			filteredOptions := []argOption{}
 			if len(argOptions) > 0 {
diff --git a/cmd/set.go b/cmd/set.go
index fef9b3f..c426948 100644
--- a/cmd/set.go
+++ b/cmd/set.go
@@ -31,19 +31,20 @@ func init() {
 		Name: "set",
 		Help: "Configures options for cmk",
 		SubCommands: map[string][]string{
-			"prompt":     {"🐵", "🐱", "random"},
-			"asyncblock": {"true", "false"},
-			"timeout":    {"600", "1800", "3600"},
-			"output":     config.GetOutputFormats(),
-			"profile":    {},
-			"url":        {},
-			"username":   {},
-			"password":   {},
-			"domain":     {},
-			"apikey":     {},
-			"secretkey":  {},
-			"verifycert": {"true", "false"},
-			"debug":      {"true", "false"},
+			"prompt":       {"🐵", "🐱", "random"},
+			"asyncblock":   {"true", "false"},
+			"timeout":      {"600", "1800", "3600"},
+			"output":       config.GetOutputFormats(),
+			"profile":      {},
+			"url":          {},
+			"username":     {},
+			"password":     {},
+			"domain":       {},
+			"apikey":       {},
+			"secretkey":    {},
+			"verifycert":   {"true", "false"},
+			"debug":        {"true", "false"},
+			"autocomplete": {"true", "false"},
 		},
 		Handle: func(r *Request) error {
 			if len(r.Args) < 1 {
diff --git a/config/config.go b/config/config.go
index 5141df6..cca7913 100644
--- a/config/config.go
+++ b/config/config.go
@@ -56,12 +56,13 @@ type ServerProfile struct {
 
 // Core block describes common options for the CLI
 type Core struct {
-	Prompt      string `ini:"prompt"`
-	AsyncBlock  bool   `ini:"asyncblock"`
-	Timeout     int    `ini:"timeout"`
-	Output      string `ini:"output"`
-	VerifyCert  bool   `ini:"verifycert"`
-	ProfileName string `ini:"profile"`
+	Prompt       string `ini:"prompt"`
+	AsyncBlock   bool   `ini:"asyncblock"`
+	Timeout      int    `ini:"timeout"`
+	Output       string `ini:"output"`
+	VerifyCert   bool   `ini:"verifycert"`
+	ProfileName  string `ini:"profile"`
+	AutoComplete bool   `ini:"autocomplete"`
 }
 
 // Config describes CLI config file and default options
@@ -141,6 +142,7 @@ func defaultCoreConfig() Core {
 		Output:      JSON,
 		VerifyCert:  true,
 		ProfileName: "localcloud",
+		AutoComplete: true,
 	}
 }
 
@@ -251,6 +253,9 @@ func saveConfig(cfg *Config) *Config {
 		// Update
 		core := new(Core)
 		conf.Section(ini.DEFAULT_SECTION).MapTo(core)
+		if (!conf.Section(ini.DEFAULT_SECTION).HasKey("autocomplete")) {
+			core.AutoComplete = true
+		}
 		cfg.Core = core
 	}
 
@@ -340,6 +345,8 @@ func (c *Config) UpdateConfig(key string, value string, update bool) {
 		} else {
 			DisableDebugging()
 		}
+	case "autocomplete":
+		c.Core.AutoComplete = value == "true"
 	default:
 		fmt.Println("Invalid option provided:", key)
 		return