-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (46 loc) · 1.4 KB
/
main.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
package main
import (
"log"
"github.com/amirhnajafiz/cemq/cmd"
"github.com/amirhnajafiz/cemq/internal/config"
"github.com/spf13/cobra"
)
func main() {
// using cobra-cli for defining commands and subcommands
root := cobra.Command{}
var (
debug bool
logs bool
server string
username string
password string
)
// add base flags
root.PersistentFlags().BoolVar(&debug, "debug", false, "enabling MQTT debug messages")
root.PersistentFlags().BoolVar(&logs, "logs-enable", true, "disabling or enabling publisher and subscriber logs")
root.PersistentFlags().StringVar(&server, "server", "", "host address of a EMQX cluster, it will override the config if you set a value to it")
root.PersistentFlags().StringVar(&username, "username", "", "a username for connecting to a EMQX, only works when the `server` is flag given")
root.PersistentFlags().StringVar(&password, "password", "", "a password for connecting to a EMQX, only works when the `server` is flag given")
// load configs
cfg, err := config.Load(server, username, password)
if err != nil {
log.Printf("failed to read context: %v", err)
}
// add commands
root.AddCommand(
cmd.Config{}.Command(),
cmd.Load{
Cfg: cfg,
Debug: debug,
Logs: logs,
}.Command(),
cmd.Cluster{
Cfg: cfg,
Debug: debug,
}.Command(),
)
// execute cobra root command
if err := root.Execute(); err != nil {
log.Fatal(err)
}
}