forked from longhorn/longhorn-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (58 loc) · 1.42 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
package main
import (
"fmt"
"os"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/longhorn/longhorn-manager/app"
)
var VERSION = "dev"
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.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})
a := cli.NewApp()
a.Version = VERSION
a.Usage = "Longhorn Manager"
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.SnapshotCmd(),
app.DeployDriverCmd(),
app.CSICommand(),
app.PostUpgradeCmd(),
app.UninstallCmd(),
// TODO: Remove MigrateForPre070VolumesCmd() after v0.8.1
app.MigrateForPre070VolumesCmd(),
}
a.CommandNotFound = cmdNotFound
a.OnUsageError = onUsageError
app.VERSION = VERSION
if err := a.Run(os.Args); err != nil {
logrus.Fatalf("Critical error: %v", err)
}
}