Make auto completion optional (#91)
* Make auto completion optional
* default autocompletion to true in absense of config
diff --git a/cli/completer.go b/cli/completer.go
index ce2b7e2..650c84b 100644
--- a/cli/completer.go
+++ b/cli/completer.go
@@ -355,23 +355,28 @@
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")
+ }
+
+ 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)
}
- 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)
-
- hasID := strings.HasSuffix(arg.Name, "id=") || strings.HasSuffix(arg.Name, "ids=")
- argOptions := buildArgOptions(response, hasID)
-
filteredOptions := []argOption{}
if len(argOptions) > 0 {
sort.Slice(argOptions, func(i, j int) bool {
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 @@
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 @@
// 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 @@
Output: JSON,
VerifyCert: true,
ProfileName: "localcloud",
+ AutoComplete: true,
}
}
@@ -251,6 +253,9 @@
// 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 @@
} else {
DisableDebugging()
}
+ case "autocomplete":
+ c.Core.AutoComplete = value == "true"
default:
fmt.Println("Invalid option provided:", key)
return