From ea9ca09f1769bb713eef2bf93fbe29ddbf6f256a 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/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 1db829c71..6a54a7837 100644 --- a/cobra/cmd/testdata/root.go.golden +++ b/cobra/cmd/testdata/root.go.golden @@ -45,7 +45,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) } } @@ -73,7 +73,7 @@ func initConfig() { // Find home directory. home, err := homedir.Dir() if err != nil { - fmt.Println(err) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } @@ -86,6 +86,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()) } } diff --git a/cobra/tpl/main.go b/cobra/tpl/main.go index 4348e5616..b5e2e1aeb 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) } } @@ -87,7 +87,7 @@ func initConfig() { // Find home directory. home, err := homedir.Dir() if err != nil { - fmt.Println(err) + fmt.Fprintln(os.Stderr, err) os.Exit(1) } @@ -100,7 +100,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 }}