Fix stderr printing functions (#894)

* Fix stderr printing functions

Follow-up of #822

* Errors go to stderr as per POSIX

* use PrintErrf() instead of extra call to Sprintf()

* Error messages should always be printed to os.Stderr.

* add test case for Print* redirection

Thanks: @bukowa for the patch.
This commit is contained in:
Alessio Treglia
2020-10-01 17:28:00 +02:00
committed by GitHub
parent 0bc8bfbe59
commit 40d34bca1b
3 changed files with 50 additions and 8 deletions

View File

@ -177,7 +177,7 @@ var rootCmd = &cobra.Command{
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}