-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (41 loc) · 1.1 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
package main
import (
"github.com/igorrius/LRP-tool/internal/cmd"
"github.com/igorrius/LRP-tool/internal/cmd/flag"
"github.com/igorrius/LRP-tool/internal/logger"
"github.com/urfave/cli/v2"
"os"
)
func main() {
app := &cli.App{
Name: "LPR tool",
Description: "Learning resources parser tool.",
Version: "v1.0.0",
Usage: "Ready for a new challenge in Goland with love!",
Before: func(ctx *cli.Context) error {
ctx.Context = logger.NewContext(
ctx.Context,
logger.NewLogger(createLoggerOptions(ctx)...))
return nil
},
Commands: []*cli.Command{
cmd.Config(),
cmd.Parser(),
},
Flags: []cli.Flag{
flag.LogLevel(),
flag.JsonOutputFormatter(),
},
}
cli.HandleExitCoder(app.Run(os.Args))
}
func createLoggerOptions(ctx *cli.Context) []logger.Option {
var opts []logger.Option
// option that set logger output formatter to JSON
if ctx.Bool(flag.JsonOutputFormatterName) {
opts = append(opts, logger.WithJsonFormatter(true))
}
// option that provide logger level
opts = append(opts, logger.WithLevel(ctx.String(flag.LogLevelName)))
return opts
}