-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
63 lines (52 loc) · 1.47 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
package main
import (
"context"
"os"
command "github.com/pPrecel/cloudagent/cmd"
"github.com/pPrecel/cloudagent/cmd/check"
"github.com/pPrecel/cloudagent/cmd/config"
"github.com/pPrecel/cloudagent/cmd/logs"
"github.com/pPrecel/cloudagent/cmd/serve"
"github.com/pPrecel/cloudagent/cmd/state"
cmd_version "github.com/pPrecel/cloudagent/cmd/version"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
var version = "local"
func main() {
o := &command.Options{
Version: version,
Context: context.Background(),
Logger: newLogger(),
}
cmd := &cobra.Command{
Use: "cloudagent",
SilenceUsage: true,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
if o.Verbose {
o.Logger.SetLevel(logrus.DebugLevel)
}
},
}
cmd.PersistentFlags().BoolVarP(&o.Verbose, "verbose", "v", false, "Displays details of actions triggered by the command.")
cmd.SetHelpCommand(&cobra.Command{Hidden: true})
cmd.AddCommand(&cobra.Command{Use: "completion", Hidden: true})
cmd.AddCommand(
config.NewCmd(config.NewOptions(o)),
serve.NewCmd(serve.NewOptions(o)),
state.NewCmd(state.NewOptions(o)),
check.NewCmd(check.NewOptions(o)),
logs.NewCmd(logs.NewOptions(o)),
cmd_version.NewCmd(o),
)
_ = cmd.Execute()
}
func newLogger() *logrus.Logger {
log := logrus.New()
log.SetOutput(os.Stdout)
formatter := new(logrus.TextFormatter)
formatter.TimestampFormat = "2006-01-02 15:04:05"
formatter.FullTimestamp = true
log.SetFormatter(formatter)
return log
}