Skip to content

Commit

Permalink
print errors to stderr in cobra init boilerplate (spf13#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brcrwilliams authored and umarcor committed Jun 7, 2019
1 parent 216ae3a commit bd812c5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cobra/cmd/testdata/root.go.golden
Expand Up @@ -47,10 +47,10 @@ to quickly create a Cobra application.`,
// 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() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}

func init() {
Expand Down Expand Up @@ -78,7 +78,7 @@ func initConfig() {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}

Expand All @@ -91,7 +91,7 @@ func initConfig() {

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
}
}

0 comments on commit bd812c5

Please sign in to comment.