From 0b3cdc8e8a339d3b3861cec96a98522c778043d9 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 (spf13/cobra#774) --- cobra/cmd/testdata/root.go.golden | 6 +++--- cobra/tpl/main.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cobra/cmd/testdata/root.go.golden b/cobra/cmd/testdata/root.go.golden index d3b889baa..45d5866a0 100644 --- a/cobra/cmd/testdata/root.go.golden +++ b/cobra/cmd/testdata/root.go.golden @@ -48,7 +48,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) } } @@ -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) } @@ -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()) } } diff --git a/cobra/tpl/main.go b/cobra/tpl/main.go index 5e5a0fae2..0df124a47 100644 --- a/cobra/tpl/main.go +++ b/cobra/tpl/main.go @@ -55,7 +55,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) } } @@ -88,7 +88,7 @@ func initConfig() { // Find home directory. home, err := homedir.Dir() if err != nil { - fmt.Println(err) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } @@ -101,7 +101,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 }}