-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCmd.go
81 lines (71 loc) · 1.34 KB
/
Cmd.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"errors"
"fmt"
"github.com/spf13/cobra"
"os"
)
var rootCmd = &cobra.Command{
Use: "sb",
Short: "Serverbench supervisor",
}
// token
var token = &cobra.Command{
Use: "token",
Short: "read/write token",
}
var tokenSet = &cobra.Command{
Use: "set",
Short: "write token",
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
// TODO bounds-of check
fmt.Println("please, provide a token")
panic(errors.New("missing token")) // lol
}
err := m.UpdateToken(args[0])
if err != nil {
fmt.Println("unable to update token")
panic(err)
}
fmt.Println(args[0])
},
}
var tokenRead = &cobra.Command{
Use: "get",
Short: "read token",
Run: func(cmd *cobra.Command, args []string) {
token, err := m.GetToken()
if err != nil {
fmt.Println("unable to read token")
panic(err)
}
fmt.Println(*token)
},
}
// run
var start = &cobra.Command{
Use: "start",
Short: "starts serverbench supervisor",
Run: func(cmd *cobra.Command, args []string) {
err := m.Init(0)
if err != nil {
fmt.Println("unable to init")
panic(err)
}
},
}
func init() {
// token
token.AddCommand(tokenRead)
token.AddCommand(tokenSet)
// root
rootCmd.AddCommand(token)
rootCmd.AddCommand(start)
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}