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 4a9db7a  config: add help docs for `set` commands (#40)
4a9db7a is described below

commit 4a9db7a55c289f0787a259a34db4a0a7343c429f
Author: Rohit Yadav <[email protected]>
AuthorDate: Tue Mar 5 14:49:54 2019 +0530

    config: add help docs for `set` commands (#40)
    
    This fixes #40, adds human readable docs for set commands and prints
    error when an invalid command is added.
    
    Signed-off-by: Rohit Yadav <[email protected]>
---
 cmd/set.go       | 12 ++++++++++--
 config/config.go |  8 +++++++-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/cmd/set.go b/cmd/set.go
index 4e2c490..207e381 100644
--- a/cmd/set.go
+++ b/cmd/set.go
@@ -19,7 +19,10 @@ package cmd
 
 import (
        "fmt"
+       "reflect"
        "strings"
+
+       "github.com/apache/cloudstack-cloudmonkey/config"
 )
 
 func init() {
@@ -44,11 +47,16 @@ func init() {
                },
                Handle: func(r *Request) error {
                        if len(r.Args) < 1 {
-                               fmt.Println("Please provide one of the 
sub-commands: ", r.Command.SubCommands)
+                               fmt.Println("Please provide one of the 
sub-commands: ", reflect.ValueOf(r.Command.SubCommands).MapKeys())
                                return nil
                        }
                        subCommand := r.Args[0]
-                       value := strings.Join(r.Args[1:], " ")
+                       value := strings.Trim(strings.Join(r.Args[1:], " "), " 
")
+                       config.Debug("Set command received:", subCommand, " 
values:", value)
+                       if r.Args[len(r.Args)-1] == "-h" {
+                               fmt.Println("Usage: set <subcommand> <option>. 
Press tab-tab to see available subcommands and options.")
+                               return nil
+                       }
                        r.Config.UpdateConfig(subCommand, value, true)
 
                        if subCommand == "profile" && r.Config.HasShell {
diff --git a/config/config.go b/config/config.go
index 4c4f0d5..17d6712 100644
--- a/config/config.go
+++ b/config/config.go
@@ -282,7 +282,10 @@ func (c *Config) UpdateConfig(key string, value string, 
update bool) {
        case "output":
                c.Core.Output = value
        case "timeout":
-               intValue, _ := strconv.Atoi(value)
+               intValue, err := strconv.Atoi(value)
+               if err != nil {
+                       fmt.Println("Error caught while setting timeout:", err)
+               }
                c.Core.Timeout = intValue
        case "profile":
                c.Core.ProfileName = value
@@ -309,6 +312,9 @@ func (c *Config) UpdateConfig(key string, value string, 
update bool) {
                } else {
                        DisableDebugging()
                }
+       default:
+               fmt.Println("Invalid option provided:", key)
+               return
        }
 
        Debug("UpdateConfig key:", key, " value:", value, " update:", update)

Reply via email to