-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
84 lines (78 loc) · 1.88 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
// fc2-live-dl-go is a tool to download FC2 Live.
package main
import (
"context"
"errors"
"os"
"github.com/Darkness4/fc2-live-dl-go/cmd/clean"
"github.com/Darkness4/fc2-live-dl-go/cmd/concat"
"github.com/Darkness4/fc2-live-dl-go/cmd/download"
"github.com/Darkness4/fc2-live-dl-go/cmd/remux"
"github.com/Darkness4/fc2-live-dl-go/cmd/watch"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
)
var version = "dev"
func init() {
log.Logger = log.Logger.Level(zerolog.InfoLevel)
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
var app = &cli.App{
Name: "fc2-live-dl-go",
Usage: "FC2 Live download.",
Version: version,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "debug",
EnvVars: []string{"DEBUG"},
Value: false,
HasBeenSet: true,
Action: func(_ *cli.Context, s bool) error {
if s {
log.Logger = log.Logger.Level(zerolog.DebugLevel)
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
return nil
},
},
&cli.BoolFlag{
Name: "trace",
EnvVars: []string{"TRACE"},
Value: false,
HasBeenSet: true,
Action: func(_ *cli.Context, s bool) error {
if s {
log.Logger = log.Logger.Level(zerolog.TraceLevel)
zerolog.SetGlobalLevel(zerolog.TraceLevel)
}
return nil
},
},
&cli.BoolFlag{
Name: "log-json",
EnvVars: []string{"LOG_JSON"},
Value: false,
HasBeenSet: true,
Action: func(_ *cli.Context, s bool) error {
if !s {
log.Logger = log.Logger.Output(zerolog.ConsoleWriter{Out: os.Stderr})
}
return nil
},
},
},
Commands: []*cli.Command{
download.Command,
watch.Command,
remux.Command,
concat.Command,
clean.Command,
},
}
func main() {
log.Logger = log.Logger.With().Caller().Logger()
if err := app.Run(os.Args); err != nil && !errors.Is(err, context.Canceled) {
log.Fatal().Err(err).Msg("application finished")
}
}