-
Notifications
You must be signed in to change notification settings - Fork 57
/
main.go
71 lines (63 loc) · 1.53 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
package main
import (
"fmt"
"os"
"path"
"runtime"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/longhorn/longhorn-instance-manager/app/cmd"
"github.com/longhorn/longhorn-instance-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.StringFlag{
Name: "url",
Value: "tcp://localhost:8500",
Usage: "specifies the server endpoint to connect to supported protocols are 'tcp' and 'unix'",
},
cli.BoolFlag{
Name: "debug",
},
cli.StringFlag{
Name: "tls-dir",
Usage: "when present will look for `tls.crt` and `tls.key` and `ca.crt` file in the specified directory",
EnvVar: "TLS_DIR",
Required: false,
},
}
a.Commands = []cli.Command{
cmd.StartCmd(),
cmd.ProcessCmd(),
cmd.VersionCmd(),
}
if err := a.Run(os.Args); err != nil {
logrus.WithError(err).Fatal("Error when executing command")
}
}