-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
58 lines (50 loc) · 1.18 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
package main
import (
"os"
"github.com/Sirupsen/logrus"
"github.com/urfave/cli/v2"
_ "go.uber.org/automaxprocs"
"github.com/pawski/go-xchange/internal/application/command"
"github.com/pawski/go-xchange/internal/logger"
)
func main() {
app := cli.NewApp()
app.Name = "XChange"
app.Version = "v0.1"
app.Description = "Application for currency rates collection"
app.Usage = ""
var debugLogging bool
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "debug, d",
Usage: "Enable debug logging",
Destination: &debugLogging,
},
}
app.Before = func(c *cli.Context) error {
logger.Get().Formatter = &logrus.TextFormatter{FullTimestamp: true}
if c.Bool("debug") {
logger.SetDebugLevel()
logger.Get().Debug("Debug logging enabled")
logger.Get().Debug(app.Name, "-", app.Version)
}
return nil
}
app.Commands = []*cli.Command{
{
Name: "collect",
Usage: "Collects currency rates",
Action: func(ctx *cli.Context) error {
return command.CollectExecute(ctx.Context, ctx.Bool("dryRun"))
},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "dryRun, r",
},
},
},
}
if err := app.Run(os.Args); err != nil {
logger.Get().Fatal(err)
}
}