From bd812c53806d31fcbfb9ba2675df3f772f1b7df2 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 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cobra/cmd/testdata/root.go.golden b/cobra/cmd/testdata/root.go.golden index d3b889baa..36afbb37c 100644 --- a/cobra/cmd/testdata/root.go.golden +++ b/cobra/cmd/testdata/root.go.golden @@ -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() { @@ -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()) } }