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/05/04 11:50:38 UTC

[cloudstack-cloudmonkey] 01/02: config: allow custom prompt

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 7e2aae2acca8f946d59ac7853e0090efe332da01
Author: Rohit Yadav <ro...@apache.org>
AuthorDate: Fri May 4 17:19:48 2018 +0530

    config: allow custom prompt
    
    Signed-off-by: Rohit Yadav <ro...@apache.org>
---
 cmd/set.go       | 1 +
 config/cache.go  | 1 +
 config/config.go | 4 ++++
 config/prompt.go | 9 ++++++---
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/cmd/set.go b/cmd/set.go
index 961decb..1755227 100644
--- a/cmd/set.go
+++ b/cmd/set.go
@@ -27,6 +27,7 @@ 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", "xml"},
diff --git a/config/cache.go b/config/cache.go
index 8fc9089..a40fdf5 100644
--- a/config/cache.go
+++ b/config/cache.go
@@ -26,6 +26,7 @@ import (
 	"unicode"
 )
 
+// FAKE is used for fake CLI only options like filter=
 const FAKE = "fake"
 
 // APIArg are the args passable to an API
diff --git a/config/config.go b/config/config.go
index 16bda15..046f134 100644
--- a/config/config.go
+++ b/config/config.go
@@ -48,6 +48,7 @@ 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"`
@@ -76,6 +77,7 @@ func getDefaultConfigDir() string {
 
 func defaultCoreConfig() Core {
 	return Core{
+		Prompt:      "🐵",
 		AsyncBlock:  false,
 		Timeout:     1800,
 		Output:      JSON,
@@ -194,6 +196,8 @@ func reloadConfig(cfg *Config) *Config {
 // UpdateConfig updates and saves config
 func (c *Config) UpdateConfig(key string, value string) {
 	switch key {
+	case "prompt":
+		c.Core.Prompt = value
 	case "asyncblock":
 		c.Core.AsyncBlock = value == "true"
 	case "output":
diff --git a/config/prompt.go b/config/prompt.go
index 83b04b1..fe002d1 100644
--- a/config/prompt.go
+++ b/config/prompt.go
@@ -36,14 +36,17 @@ func emoji() string {
 	return emojis[rand.Intn(len(emojis)-1)]
 }
 
-func promptMoji() string {
+func renderPrompt(prompt string) string {
 	if runtime.GOOS == "windows" {
 		return "cmk"
 	}
-	return emoji() // 🐒
+	if prompt == "random" {
+		return emoji()
+	}
+	return prompt
 }
 
 // GetPrompt returns prompt that the CLI should use
 func (c *Config) GetPrompt() string {
-	return fmt.Sprintf("(%s) %s > ", c.Core.ProfileName, promptMoji())
+	return fmt.Sprintf("(%s) %s > ", c.Core.ProfileName, renderPrompt(c.Core.Prompt))
 }

-- 
To stop receiving notification emails like this one, please contact
rohit@apache.org.