Skip to content

Commit

Permalink
cobra init: Should exit on invalid configuration
Browse files Browse the repository at this point in the history
Merge spf13/cobra#1583

Closes #184
  • Loading branch information
andreaangiolillo authored and hoshsadiq committed Feb 8, 2022
1 parent ceec0c8 commit 212ce0c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cobra/cmd/root.go
Expand Up @@ -73,7 +73,10 @@ func initConfig() {

viper.AutomaticEnv()

if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
if err := viper.ReadInConfig(); err != nil {
cobra.CheckErr(err)
}

_, err := fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
cobra.CheckErr(err)
}

0 comments on commit 212ce0c

Please sign in to comment.