-
Notifications
You must be signed in to change notification settings - Fork 35
/
main.go
61 lines (53 loc) · 1.17 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
package main
import (
"fmt"
"os"
"path"
"runtime"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/longhorn/backing-image-manager/app/cmd"
"github.com/longhorn/backing-image-manager/pkg/meta"
)
// following variables will be filled by `-ldflags "-X ..."`
var (
Version string
GitCommit string
BuildDate string
)
func main() {
a := cli.NewApp()
a.Version = Version
meta.Version = Version
meta.GitCommit = GitCommit
meta.BuildDate = BuildDate
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.Before = func(c *cli.Context) error {
if c.GlobalBool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
}
a.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
},
}
a.Commands = []cli.Command{
cmd.StartCmd(),
cmd.BackingImageCmd(),
cmd.DataSourceCmd(),
VersionCmd(),
}
if err := a.Run(os.Args); err != nil {
logrus.Fatal("Error when executing command: ", err)
}
}