-
Notifications
You must be signed in to change notification settings - Fork 151
/
main.go
79 lines (69 loc) · 1.74 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
package main
import (
"fmt"
"os"
"path"
"runtime"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/longhorn/longhorn-manager/app"
"github.com/longhorn/longhorn-manager/meta"
)
func cmdNotFound(c *cli.Context, command string) {
panic(fmt.Errorf("unrecognized command: %s", command))
}
func onUsageError(c *cli.Context, err error, isSubcommand bool) error {
panic(fmt.Errorf("usage error, please check your command"))
}
func main() {
logrus.SetReportCaller(true)
logrus.SetFormatter(&logrus.TextFormatter{
CallerPrettyfier: func(f *runtime.Frame) (function string, file string) {
fileName := fmt.Sprintf("%s:%d", path.Base(f.File), f.Line)
funcName := path.Base(f.Function)
return funcName, fileName
},
FullTimestamp: true,
})
a := cli.NewApp()
a.Usage = "Longhorn Manager"
a.Version = meta.Version
a.Before = func(c *cli.Context) error {
if c.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}
if c.GlobalBool("log-json") {
logrus.SetFormatter(&logrus.JSONFormatter{})
}
return nil
}
a.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug, d",
Usage: "enable debug logging level",
EnvVar: "RANCHER_DEBUG",
},
cli.BoolFlag{
Name: "log-json, j",
Usage: "log in json format",
EnvVar: "RANCHER_LOG_JSON",
},
}
a.Commands = []cli.Command{
app.DaemonCmd(),
app.RecurringJobCmd(),
app.DeployDriverCmd(),
app.CSICommand(),
app.PreUpgradeCmd(),
app.PostUpgradeCmd(),
app.UninstallCmd(),
app.SystemRolloutCmd(),
// TODO: Remove MigrateForPre070VolumesCmd() after v0.8.1
app.MigrateForPre070VolumesCmd(),
}
a.CommandNotFound = cmdNotFound
a.OnUsageError = onUsageError
if err := a.Run(os.Args); err != nil {
logrus.Fatalf("Critical error: %v", err)
}
}