-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
96 lines (87 loc) · 2.46 KB
/
main.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/filecoin-project/dealbot/commands"
"github.com/filecoin-project/dealbot/version"
logging "github.com/ipfs/go-log/v2"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
)
var log = logging.Logger("dealbot")
func main() {
// Set up a context that is canceled when the command is interrupted
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// Set up a signal handler to cancel the context
go func() {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, syscall.SIGTERM, syscall.SIGINT)
select {
case <-interrupt:
cancel()
case <-ctx.Done():
}
}()
if err := logging.SetLogLevel("*", "info"); err != nil {
log.Fatal(err)
}
appFlags := append(commands.CommonFlags, []cli.Flag{
altsrc.NewStringFlag(&cli.StringFlag{
Name: "api",
EnvVars: []string{"FULLNODE_API_INFO"},
Value: "",
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "lotus-path",
EnvVars: []string{"LOTUS_PATH"},
Value: "",
Usage: "Set the lotus path instead of the API determine the api url automatically",
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "log-level",
EnvVars: []string{"GOLOG_LOG_LEVEL"},
Value: "debug",
Usage: "Set the default log level for all loggers to `LEVEL`",
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "log-level-named",
EnvVars: []string{"DEALBOT_LOG_LEVEL_NAMED"},
Value: "",
Usage: "A comma delimited list of named loggers and log levels formatted as name:level, for example 'logger1:debug,logger2:info'",
}),
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
},
}...)
app := &cli.App{
Name: "dealbot",
Usage: "Filecoin Network Storage and Retrieval Analysis Utility",
Version: version.String(),
Flags: appFlags,
Commands: []*cli.Command{
commands.MakeStorageDealCmd,
commands.MakeRetrievalDealCmd,
commands.MockCmd,
commands.MockTasksCmd,
commands.DaemonCmd,
commands.ControllerCmd,
commands.QueueRetrievalCmd,
commands.QueueStorageCmd,
commands.DrainCmd,
},
Before: altsrc.InitInputSourceWithContext(append(appFlags, commands.AllFlags...), altsrc.NewYamlSourceFromFlagFunc("config")),
}
if _, ok := os.LookupEnv("DEALBOT_LOG_JSON"); ok {
logging.SetupLogging(logging.Config{
Format: logging.JSONOutput,
Stdout: true,
})
}
if err := app.RunContext(ctx, os.Args); err != nil {
log.Fatal(err)
}
}