-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
49 lines (42 loc) · 1.1 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
package main
import (
"fmt"
"os"
"github.com/rkonfj/toh/cmd/acl"
"github.com/rkonfj/toh/cmd/overlay"
"github.com/rkonfj/toh/cmd/pf"
"github.com/rkonfj/toh/cmd/s5"
"github.com/rkonfj/toh/cmd/serve"
"github.com/rkonfj/toh/spec"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func main() {
cmd := &cobra.Command{
Use: "toh",
Version: fmt.Sprintf("%s, commit %s", spec.Version, spec.Commit),
Short: "A tcp/udp over http/websocket toolset",
PersistentPreRunE: initAction,
}
cmd.AddCommand(acl.Cmd)
cmd.AddCommand(overlay.Cmd)
cmd.AddCommand(pf.Cmd)
cmd.AddCommand(s5.Cmd)
cmd.AddCommand(serve.Cmd)
cmd.PersistentFlags().String("log-level", "info", "logrus logger level")
cmd.Execute()
}
func initAction(cmd *cobra.Command, args []string) error {
logLevel, err := cmd.Flags().GetString("log-level")
if err != nil {
return err
}
ll, err := logrus.ParseLevel(logLevel)
if err != nil {
return err
}
logrus.SetLevel(ll)
logrus.SetOutput(os.Stdout)
logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true, DisableColors: true})
return nil
}