-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
48 lines (39 loc) · 1004 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
package cli
import (
"fmt"
"github.com/knoebber/dotfile/local"
"gopkg.in/alecthomas/kingpin.v2"
)
type configCommand struct {
key string
value string
}
func (cc *configCommand) run(*kingpin.ParseContext) error {
if cc.key != "" && cc.value != "" {
return local.SetConfig(flags.configPath, cc.key, cc.value)
}
config, err := local.ReadConfig(flags.configPath)
if err != nil {
return err
}
if cc.key == "remote" {
fmt.Println(config.Remote)
} else if cc.key == "username" {
fmt.Println(config.Username)
} else if cc.key == "token" {
fmt.Println(config.Token)
} else {
fmt.Println(config)
}
return nil
}
func addConfigSubCommandToApplication(app *kingpin.Application) {
cc := new(configCommand)
p := app.Command("config", "set or print dotfile configurations").Action(cc.run)
p.Arg("key", "the config key to change or print - <remote/username/token>").EnumVar(&cc.key,
"remote",
"username",
"token",
)
p.Arg("value", "the new value").StringVar(&cc.value)
}