-
Notifications
You must be signed in to change notification settings - Fork 53
/
cmd.go
40 lines (31 loc) · 955 Bytes
/
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
// Package cmd provides the cli for running the monitor service
package cmd
import (
libcmd "github.com/omni-network/omni/lib/cmd"
"github.com/omni-network/omni/lib/log"
monitor "github.com/omni-network/omni/monitor/app"
"github.com/spf13/cobra"
)
// New returns a new root cobra command that handles our command line tool.
func New() *cobra.Command {
cmd := libcmd.NewRootCmd(
"monitor",
"Service that monitors Omni network metrics not measured in individual apps (e.g. smart contracts).",
)
cfg := monitor.DefaultConfig()
bindRunFlags(cmd.Flags(), &cfg)
bindLoadGenFlags(cmd.Flags(), &cfg.LoadGen)
logCfg := log.DefaultConfig()
log.BindFlags(cmd.Flags(), &logCfg)
cmd.RunE = func(cmd *cobra.Command, _ []string) error {
ctx, err := log.Init(cmd.Context(), logCfg)
if err != nil {
return err
}
if err := libcmd.LogFlags(ctx, cmd.Flags()); err != nil {
return err
}
return monitor.Run(ctx, cfg)
}
return cmd
}