-
Notifications
You must be signed in to change notification settings - Fork 3
/
root.go
77 lines (61 loc) · 2.41 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/myfintech/ark/src/go/lib/log"
"github.com/spf13/viper"
"github.com/myfintech/ark/src/go/lib/arksdk/target/base"
)
var workspace = base.NewWorkspace()
// rootCmd represents the base command when called without any sub-commands
var rootCmd = &cobra.Command{
Use: "ark",
Short: "ark is the command line interface to interact with the arksdk",
SilenceUsage: true,
SilenceErrors: true,
}
func RootCmd() *cobra.Command {
return rootCmd
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
defer func() {
if err := recover(); err != nil {
if viper.GetBool("debug") {
panic(err)
}
fmt.Println(err)
os.Exit(1)
}
}()
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
rootCmd.PersistentFlags().String("log_level", "info", "Logging level. Supports 'trace', 'debug', 'info', 'warn', 'error', and 'fatal'")
rootCmd.PersistentFlags().String("log_format", "text", "The log output format. Supports 'text' and 'json'")
rootCmd.PersistentFlags().Bool("skip_version_check", false, "Skip the version check when calling ark")
rootCmd.PersistentFlags().Bool("debug", false, "Captures a more detailed stack trace on error if there was a panic")
rootCmd.PersistentFlags().StringP("namespace", "n", "", "Defines what namespace should be used for Kubernetes actions")
rootCmd.PersistentFlags().String("environment", "", "Defines what environment should be considered for configuration loading")
rootCmd.PersistentFlags().String("cpu_profile", "", "Runs benchmarks against cpu usage")
rootCmd.PersistentFlags().String("mem_profile", "", "Runs benchmarks against memory usage")
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
_ = viper.BindPFlags(rootCmd.PersistentFlags())
}
// initConfig reads in config file and ENV variables if set.
func initConfig() {
viper.SetEnvPrefix("")
viper.AutomaticEnv() // read in environment variables that match
log.Init()
}