-
Notifications
You must be signed in to change notification settings - Fork 90
/
root.go
48 lines (38 loc) · 862 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cli
import (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
func RootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "kotsadm",
Short: "kotsadm is the Admin Console for KOTS",
Long: ``,
Args: cobra.MinimumNArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlags(cmd.Flags())
},
RunE: func(cmd *cobra.Command, args []string) error {
return nil
},
}
cobra.OnInitialize(initConfig)
cmd.PersistentFlags().String("log-level", "info", "set the log level")
cmd.AddCommand(APICmd())
cmd.AddCommand(CompletionCmd())
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
return cmd
}
func InitAndExecute() {
if err := RootCmd().Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func initConfig() {
viper.SetEnvPrefix("KOTSADM")
viper.AutomaticEnv()
}