-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathmain.go
50 lines (38 loc) · 1023 Bytes
/
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
package main // import "github.com/costela/wesher"
import (
"fmt"
"os"
"github.com/alecthomas/kong"
"github.com/sirupsen/logrus"
)
var version = "dev"
type cli struct {
LogLevel LogLevelFlag `env:"WESHER_LOG_LEVEL" help:"set the verbosity (debug/info/warn/error)" default:"warn"`
Version VersionFlag `help:"display current version and exit"`
Agent AgentCmd `cmd:"" default:"withargs" help:"start the wesher agent (default when no command specified)"`
}
func main() {
cli := &cli{}
ktx := kong.Parse(cli,
kong.Name("wesher"),
kong.Description("mesh overlay network manager"),
kong.UsageOnError(),
)
err := ktx.Run(cli)
ktx.FatalIfErrorf(err)
}
type VersionFlag bool
func (v *VersionFlag) BeforeApply() error {
fmt.Println(version)
os.Exit(0)
return nil
}
type LogLevelFlag string
func (l LogLevelFlag) AfterApply() error {
logLevel, err := logrus.ParseLevel(string(l))
if err != nil {
logrus.WithError(err).Fatal("could not parse loglevel")
}
logrus.SetLevel(logLevel)
return nil
}