forked from sensu/sensu-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
34 lines (27 loc) · 819 Bytes
/
root.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
package cmd
import (
"context"
"strings"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// NewRootCommand creates a new root sensu-agent command. The context provided
// is used for cancellation. The args are parsed with cobra. The first argument
// is assumed to be the binary name and is ignored.
func NewRootCommand(ctx context.Context, args []string) *cobra.Command {
cmd := &cobra.Command{
Use: "sensu-agent",
Short: "sensu agent",
}
logrus.SetFormatter(&logrus.JSONFormatter{})
logger := logrus.WithFields(logrus.Fields{
"component": "cmd",
})
cmd.AddCommand(newVersionCommand())
cmd.AddCommand(newStartCommand(ctx, args, logger))
viper.SetEnvPrefix("sensu")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
viper.AutomaticEnv()
return cmd
}