forked from longhorn/longhorn-engine
/
main.go
80 lines (71 loc) · 1.56 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
package main
import (
"fmt"
"log"
"os"
"runtime/pprof"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/docker/docker/pkg/reexec"
"github.com/rancher/longhorn/app"
"github.com/rancher/longhorn/backup"
"github.com/rancher/sparse-tools/cli/sfold"
"github.com/rancher/sparse-tools/cli/ssync"
)
func main() {
reexec.Register("ssync", ssync.Main)
reexec.Register("sfold", sfold.Main)
reexec.Register("sbackup", backup.Main)
if !reexec.Init() {
longhornCli()
}
}
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 longhornCli() {
pprofFile := os.Getenv("PPROFILE")
if pprofFile != "" {
f, err := os.Create(pprofFile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
a := cli.NewApp()
a.Before = func(c *cli.Context) error {
if c.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
}
a.Flags = []cli.Flag{
cli.StringFlag{
Name: "url",
Value: "http://localhost:9501",
},
cli.BoolFlag{
Name: "debug",
},
}
a.Commands = []cli.Command{
app.ControllerCmd(),
app.ReplicaCmd(),
app.SyncAgentCmd(),
app.AddReplicaCmd(),
app.LsReplicaCmd(),
app.RmReplicaCmd(),
app.SnapshotCmd(),
app.BackupCmd(),
app.Journal(),
}
a.CommandNotFound = cmdNotFound
a.OnUsageError = onUsageError
if err := a.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}