Tidied up environment var related code

This commit is contained in:
David J. Allen 2024-05-06 17:25:04 -06:00
parent 2d982d2bb6
commit 198da56791
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
4 changed files with 50 additions and 7 deletions

View file

@ -31,7 +31,6 @@ var rootCmd = &cobra.Command{
}
func Execute() {
initialize()
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "failed to start CLI: %s", err)
os.Exit(1)
@ -39,14 +38,19 @@ func Execute() {
}
func init() {
rootCmd.PersistentFlags().BoolVarP(&config.Options.Verbose, "verbose", "v", false, "set the verbose flag")
cobra.OnInitialize(initialize)
rootCmd.PersistentFlags().BoolVarP(&config.Options.Verbose, "verbose", "v", config.Options.Verbose, "set the verbose flag")
rootCmd.PersistentFlags().StringVarP(&confPath, "config", "c", "", "set the config path")
rootCmd.PersistentFlags().StringVar(&config.Options.CachePath, "cache", "", "set the cache path")
}
func initialize() {
initConfig()
initEnv()
err := initEnv()
if err != nil {
fmt.Println(err)
fmt.Println("WARNING: Ignoring environment variables with errors.")
}
}
func initConfig() {