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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package cli
import (
"fmt"
"os"
"github.com/ethereum-optimism/optimism/indexer/config"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/urfave/cli/v2"
)
type Cli struct {
GitVersion string
GitCommit string
GitDate string
app *cli.App
Flags []cli.Flag
}
func runIndexer(ctx *cli.Context) error {
configPath := ctx.String(ConfigFlag.Name)
conf, err := config.LoadConfig(configPath)
fmt.Println(conf)
if err != nil {
log.Crit("Failed to load config", "message", err)
}
// finish me
return nil
}
func runApi(ctx *cli.Context) error {
configPath := ctx.String(ConfigFlag.Name)
conf, err := config.LoadConfig(configPath)
fmt.Println(conf)
if err != nil {
log.Crit("Failed to load config", "message", err)
}
// finish me
return nil
}
var (
ConfigFlag = &cli.StringFlag{
Name: "config",
Value: "./indexer.toml",
Aliases: []string{"c"},
Usage: "path to config file",
EnvVars: []string{"INDEXER_CONFIG"},
}
// Not used yet. Use this flag to run legacy app instead
// Remove me after indexer is released
IndexerRefreshFlag = &cli.BoolFlag{
Name: "indexer-refresh",
Value: false,
Aliases: []string{"i"},
Usage: "run new unreleased indexer by passing in flag",
EnvVars: []string{"INDEXER_REFRESH"},
}
)
// make a instance method on Cli called Run that runs cli
// and returns an error
func (c *Cli) Run(args []string) error {
return c.app.Run(args)
}
func NewCli(GitVersion string, GitCommit string, GitDate string) *Cli {
log.Root().SetHandler(
log.LvlFilterHandler(
log.LvlInfo,
log.StreamHandler(os.Stdout, log.TerminalFormat(true)),
),
)
flags := []cli.Flag{
ConfigFlag,
}
app := &cli.App{
Version: fmt.Sprintf("%s-%s", GitVersion, params.VersionWithCommit(GitCommit, GitDate)),
Description: "An indexer of all optimism events with a serving api layer",
Commands: []*cli.Command{
{
Name: "api",
Flags: flags,
Description: "Runs the api service",
Action: runApi,
},
{
Name: "indexer",
Flags: flags,
Description: "Runs the indexing service",
Action: runIndexer,
},
},
}
return &Cli{
app: app,
Flags: flags,
}
}