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/11/30 18:23:30 UTC
[cloudstack-cloudmonkey] 02/02: cli: allow parameter completion to
be disables
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
commit b00b8b1772e0fa6c044b75a1910084fdd6afde78
Author: Rohit Yadav <ro...@apache.org>
AuthorDate: Fri Nov 30 23:51:54 2018 +0530
cli: allow parameter completion to be disables
This adds the `paramcompletion` setting from python based cloudmonkey
to allow disabling of go-prompt based parameter completion logic.
This also ensure that when cursor is moved back completion won't be
shown to minimize distraction.
Fixes #32
Signed-off-by: Rohit Yadav <ro...@apache.org>
---
cli/completer.go | 6 ++++++
cmd/set.go | 26 ++++++++++++++------------
config/config.go | 28 ++++++++++++++++------------
3 files changed, 36 insertions(+), 24 deletions(-)
diff --git a/cli/completer.go b/cli/completer.go
index 29c944f..c2a592f 100644
--- a/cli/completer.go
+++ b/cli/completer.go
@@ -71,6 +71,12 @@ func inArray(s string, array []string) bool {
var cachedResponse map[string]interface{}
func completer(in prompt.Document) []prompt.Suggest {
+ if !cfg.Core.ParamCompletion {
+ return []prompt.Suggest{}
+ }
+ if in.TextBeforeCursor() == "" || len(strings.TrimRight(in.TextAfterCursor(), " ")) > 0 {
+ return []prompt.Suggest{}
+ }
args := strings.Split(strings.TrimLeft(in.TextBeforeCursor(), " "), " ")
for i := range args {
diff --git a/cmd/set.go b/cmd/set.go
index c500190..2580a62 100644
--- a/cmd/set.go
+++ b/cmd/set.go
@@ -27,18 +27,20 @@ func init() {
Name: "set",
Help: "Configures options for cmk",
SubCommands: map[string][]string{
- "prompt": {"🐵", "🐱", "random"},
- "asyncblock": {"true", "false"},
- "timeout": {"600", "1800", "3600"},
- "output": {"json", "text", "table", "column", "csv"},
- "profile": {},
- "url": {},
- "username": {},
- "password": {},
- "domain": {},
- "apikey": {},
- "secretkey": {},
- "verifycert": {"true", "false"},
+ "prompt": {"🐵", "🐱", "random"},
+ "asyncblock": {"true", "false"},
+ "timeout": {"600", "1800", "3600"},
+ "output": {"json", "text", "table", "column", "csv"},
+ "profile": {},
+ "url": {},
+ "username": {},
+ "password": {},
+ "domain": {},
+ "apikey": {},
+ "secretkey": {},
+ "paramcompletion": {"true", "false"},
+ "verifycert": {"true", "false"},
+ "debug": {"true", "false"},
},
Handle: func(r *Request) error {
if len(r.Args) < 1 {
diff --git a/config/config.go b/config/config.go
index 94dd01a..f0eafad 100644
--- a/config/config.go
+++ b/config/config.go
@@ -54,12 +54,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"`
+ ParamCompletion bool `ini:"paramcompletion"`
+ VerifyCert bool `ini:"verifycert"`
+ ProfileName string `ini:"profile"`
}
// Config describes CLI config file and default options
@@ -93,12 +94,13 @@ func getDefaultConfigDir() string {
func defaultCoreConfig() Core {
return Core{
- Prompt: "🐱",
- AsyncBlock: true,
- Timeout: 1800,
- Output: JSON,
- VerifyCert: true,
- ProfileName: "localcloud",
+ Prompt: "🐱",
+ AsyncBlock: true,
+ Timeout: 1800,
+ Output: JSON,
+ ParamCompletion: true,
+ VerifyCert: true,
+ ProfileName: "localcloud",
}
}
@@ -263,6 +265,8 @@ func (c *Config) UpdateConfig(key string, value string, update bool) {
c.ActiveProfile.APIKey = value
case "secretkey":
c.ActiveProfile.SecretKey = value
+ case "paramcompletion":
+ c.Core.ParamCompletion = value == "true"
case "verifycert":
c.Core.VerifyCert = value == "true"
case "debug":