-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (48 loc) · 1.06 KB
/
main.go
File metadata and controls
58 lines (48 loc) · 1.06 KB
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
package main
import (
"errors"
"log"
"os"
"github.com/flashbots/go-template/common"
"github.com/urfave/cli/v2" // imports as package "cli"
)
var flags []cli.Flag = []cli.Flag{
&cli.BoolFlag{
Name: "log-json",
Value: false,
Usage: "log in JSON format",
},
&cli.BoolFlag{
Name: "log-debug",
Value: false,
Usage: "log debug messages",
},
}
func main() {
app := &cli.App{
Name: "cli",
Usage: "command-line interface for your project",
Version: common.Version,
HideVersion: false,
Flags: flags,
Action: runCli,
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func runCli(cCtx *cli.Context) error {
logJSON := cCtx.Bool("log-json")
logDebug := cCtx.Bool("log-debug")
log := common.SetupLogger(&common.LoggingOpts{
Debug: logDebug,
JSON: logJSON,
Version: common.Version,
})
log.Info("Starting the project")
log.Debug("debug message")
log.Info("info message")
log.With("key", "value").Warn("warn message")
log.Error("error message", "err", errors.ErrUnsupported)
return nil
}