-
Notifications
You must be signed in to change notification settings - Fork 3
/
cmdline.go
52 lines (46 loc) · 1.14 KB
/
cmdline.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
50
51
52
package main
import (
"fmt"
"github.com/urfave/cli/v2"
)
func ConfigCmd(defaultAction func(*cli.Context) error) *cli.App {
return &cli.App{
Action: defaultAction, // only run if no sub command
// run if sub command not correct
CommandNotFound: func(context *cli.Context, s string) {
fmt.Println("command not find, use -h or --help show help")
},
Commands: []*cli.Command{
{
Name: "config",
Usage: "config command",
Subcommands: []*cli.Command{
{
Name: "get_token",
Usage: "get token",
Action: func(clictx *cli.Context) error {
appConfig := loadConfig(BINARY_DIR)
fmt.Println(appConfig.cfg.Token)
return nil
},
},
{
Name: "set",
Usage: "set token",
Flags: []cli.Flag{
&cli.StringFlag{Name: "token", Required: false},
},
Action: func(clictx *cli.Context) error {
// Change value in map and marshal back into yaml
tokenSet := clictx.String("token")
appConfig := loadConfig(BINARY_DIR)
appConfig.cfg.Token = tokenSet
appConfig.updateConfig()
return nil
},
},
},
},
},
}
}