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 <rohit.yadav@shapeblue.com>
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 @@
import (
"fmt"
+ "reflect"
"strings"
+
+ "github.com/apache/cloudstack-cloudmonkey/config"
)
func init() {
@@ -44,11 +47,16 @@
},
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 @@
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 @@
} else {
DisableDebugging()
}
+ default:
+ fmt.Println("Invalid option provided:", key)
+ return
}
Debug("UpdateConfig key:", key, " value:", value, " update:", update)