From 4cae044922a8b290ff7a64562553a8cbff3bcd0c Mon Sep 17 00:00:00 2001 From: Brian Williams Date: Sat, 20 Oct 2018 18:14:02 -0500 Subject: [PATCH] print errors to stderr in `cobra init` boilerplate (#774) --- cobra/cmd/init.go | 6 +++--- cobra/cmd/testdata/root.go.golden | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cobra/cmd/init.go b/cobra/cmd/init.go index d65e6c8c59..7f0a21159f 100644 --- a/cobra/cmd/init.go +++ b/cobra/cmd/init.go @@ -169,7 +169,7 @@ to quickly create a Cobra application.` + "`" + `, // 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) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } } @@ -197,7 +197,7 @@ func initConfig() { // Find home directory. home, err := homedir.Dir() if err != nil { - fmt.Println(err) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } @@ -210,7 +210,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()) } }{{ end }} ` diff --git a/cobra/cmd/testdata/root.go.golden b/cobra/cmd/testdata/root.go.golden index d74f4cd450..6b82106ad2 100644 --- a/cobra/cmd/testdata/root.go.golden +++ b/cobra/cmd/testdata/root.go.golden @@ -44,7 +44,7 @@ to quickly create a Cobra application.`, // 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) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } } @@ -71,7 +71,7 @@ func initConfig() { // Find home directory. home, err := homedir.Dir() if err != nil { - fmt.Println(err) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } @@ -84,6 +84,6 @@ 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()) } }