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 Mar 20, 2019
1 parent ba7e68a commit 4cae044
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions cobra/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 }}
`
Expand Down
6 changes: 3 additions & 3 deletions cobra/cmd/testdata/root.go.golden
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}

Expand All @@ -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())
}
}

0 comments on commit 4cae044

Please sign in to comment.