/
webds.go
74 lines (67 loc) · 1.56 KB
/
webds.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
package main
import (
"github.com/urfave/cli/v2"
"github.com/veypi/utils/cmd"
"github.com/veypi/utils/log"
"github.com/veypi/webds"
client "github.com/veypi/webds/client/go.client"
"os"
)
var cfg = &struct {
LogLevel string
Host string
ID string
}{
ID: "admin",
Host: "ws://127.0.0.1:10086",
LogLevel: "info",
}
const appName = "webds"
var cfgPath = cmd.GetCfgPath(appName, appName)
func main() {
cmd.LoadCfg(cfgPath, cfg)
app := cmd.NewCli(appName, cfg, cfgPath)
app.Version = webds.Version
app.Usage = "webds command tool, which is valid in server's host."
app.Flags = append(app.Flags,
&cli.StringFlag{
Name: "log_level",
Usage: "trace/debug/info/warn/error/fatal/panic",
Value: cfg.LogLevel,
Destination: &cfg.LogLevel,
},
&cli.StringFlag{
Name: "host",
Usage: "the server address",
Value: cfg.Host,
Destination: &cfg.Host,
},
&cli.StringFlag{
Name: "id",
Aliases: []string{"i"},
Usage: "the client id",
Value: cfg.ID,
Destination: &cfg.ID,
},
)
app.Commands = append(app.Commands,
Topic,
Node,
Cluster,
Scan,
)
app.Before = func(c *cli.Context) error {
//log.DisableCaller()
if l, err := log.ParseLevel(cfg.LogLevel); err != nil {
log.Warn().Str("level", cfg.LogLevel).Msg("log level is not right")
} else {
log.SetLevel(l)
log.Debug().Msg("set log level to " + l.String())
}
return nil
}
_ = app.Run(os.Args)
}
func newConn() (webds.Connection, error) {
return client.NewFromUrl(cfg.ID, cfg.Host, nil)
}