-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
66 lines (55 loc) · 1.46 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
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"github.com/vshn/appcat/v4/cmd"
)
func init() {
rootCmd.AddCommand(
cmd.ControllerCMD,
cmd.SLIProberCMD,
cmd.FunctionCMD,
cmd.MaintenanceCMD,
cmd.SlareportCMD,
cmd.APIServerCMD,
)
}
func main() {
cmd, _, err := rootCmd.Find(os.Args[1:])
// default to functions if no cmd is given
// necessary to properly support `crank render`
// from https://github.com/spf13/cobra/issues/823#issuecomment-870027246
if err == nil && cmd.Use == rootCmd.Use && cmd.Flags().Parse(os.Args[1:]) != pflag.ErrHelp {
args := append([]string{"functions"}, os.Args[1:]...)
rootCmd.SetArgs(args)
}
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
var (
logLevel int
logFormat string
rootCmd = &cobra.Command{
Short: "AppCat",
Long: "AppCat controllers, api servers, grpc servers and probers",
PersistentPreRunE: setupLogging,
Use: "appcat",
}
)
func init() {
rootCmd.PersistentFlags().IntVarP(&logLevel, "log-level", "v", 0, "Number of the log level verbosity.")
rootCmd.PersistentFlags().StringVar(&logFormat, "log-format", "console", "Sets the log format (values: [json, console]).")
viper.AutomaticEnv()
}
func setupLogging(cmd *cobra.Command, _ []string) error {
err := SetupLogging(cmd, logLevel, logFormat)
if err != nil {
return err
}
return LogMetadata(cmd)
}