-
Notifications
You must be signed in to change notification settings - Fork 31
/
cmd.go
50 lines (40 loc) · 1.39 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
// Package cmd provides the cli for running the indexer.
package cmd
import (
"github.com/omni-network/omni/explorer/indexer/app"
libcmd "github.com/omni-network/omni/lib/cmd"
"github.com/omni-network/omni/lib/log"
"github.com/omni-network/omni/lib/netconf"
"github.com/omni-network/omni/lib/xchain"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
// New returns a new root cobra command that handles our command line tool.
func New() *cobra.Command {
cmd := libcmd.NewRootCmd(
"indexer",
"Indexer is a service that will initialize our streams to listen to our portals and index "+
"data and put it in our Omni Blocks DB",
)
cfg := app.DefaultConfig()
bindIndexerFlags(cmd.Flags(), &cfg)
logCfg := log.DefaultConfig()
log.BindFlags(cmd.Flags(), &logCfg)
cmd.RunE = func(cmd *cobra.Command, args []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 app.Run(ctx, cfg)
}
return cmd
}
func bindIndexerFlags(flags *pflag.FlagSet, cfg *app.Config) {
netconf.BindFlag(flags, &cfg.Network)
xchain.BindFlags(flags, &cfg.RPCEndpoints)
flags.StringVar(&cfg.ExplorerDBConn, "explorer-db-conn", cfg.ExplorerDBConn, "URL to the database")
flags.StringVar(&cfg.MonitoringAddr, "monitoring-addr", cfg.MonitoringAddr, "The address to bind the monitoring server")
}