Skip to content

Commit 4a9db7a

Browse files
committed
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>
1 parent ace8e64 commit 4a9db7a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

cmd/set.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ package cmd
1919

2020
import (
2121
"fmt"
22+
"reflect"
2223
"strings"
24+
25+
"github.com/apache/cloudstack-cloudmonkey/config"
2326
)
2427

2528
func init() {
@@ -44,11 +47,16 @@ func init() {
4447
},
4548
Handle: func(r *Request) error {
4649
if len(r.Args) < 1 {
47-
fmt.Println("Please provide one of the sub-commands: ", r.Command.SubCommands)
50+
fmt.Println("Please provide one of the sub-commands: ", reflect.ValueOf(r.Command.SubCommands).MapKeys())
4851
return nil
4952
}
5053
subCommand := r.Args[0]
51-
value := strings.Join(r.Args[1:], " ")
54+
value := strings.Trim(strings.Join(r.Args[1:], " "), " ")
55+
config.Debug("Set command received:", subCommand, " values:", value)
56+
if r.Args[len(r.Args)-1] == "-h" {
57+
fmt.Println("Usage: set <subcommand> <option>. Press tab-tab to see available subcommands and options.")
58+
return nil
59+
}
5260
r.Config.UpdateConfig(subCommand, value, true)
5361

5462
if subCommand == "profile" && r.Config.HasShell {

config/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,10 @@ func (c *Config) UpdateConfig(key string, value string, update bool) {
282282
case "output":
283283
c.Core.Output = value
284284
case "timeout":
285-
intValue, _ := strconv.Atoi(value)
285+
intValue, err := strconv.Atoi(value)
286+
if err != nil {
287+
fmt.Println("Error caught while setting timeout:", err)
288+
}
286289
c.Core.Timeout = intValue
287290
case "profile":
288291
c.Core.ProfileName = value
@@ -309,6 +312,9 @@ func (c *Config) UpdateConfig(key string, value string, update bool) {
309312
} else {
310313
DisableDebugging()
311314
}
315+
default:
316+
fmt.Println("Invalid option provided:", key)
317+
return
312318
}
313319

314320
Debug("UpdateConfig key:", key, " value:", value, " update:", update)

0 commit comments

Comments
 (0)