-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (43 loc) · 957 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"os/user"
"strconv"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
func config(c *cli.Context) {
if !c.Bool("list") && len(c.Args()) != 2 {
cli.ShowCommandHelp(c, "config")
return
}
var file = ".settings.yml"
if c.Bool("global") {
user, err := user.Current()
if err != nil {
log.Fatalf("Failed to get user's home directory: %s", err)
}
file = user.HomeDir + "/.cf.yml"
}
settings, err := ReadKeyValueYamlFile(file)
if err != nil {
log.Fatalf("Failed to read file: %s", err)
}
if c.Bool("list") {
for k, v := range settings {
fmt.Printf("%s=%v\n", k, v)
}
return
}
key := c.Args()[0]
var value interface{}
if v, err := strconv.ParseInt(c.Args()[1], 10, 64); err == nil {
value = v
} else {
value = c.Args()[1]
}
settings[key] = value
if err = WriteKeyValueYamlFile(file, settings); err != nil {
log.Fatalf("Failed to write settings file: %s", err)
}
}