mirror of
https://github.com/spf13/cobra
synced 2025-05-06 05:17:21 +00:00
Print errors to stderr in cobra init
boilerplate
This commit is contained in:
parent
40172f1635
commit
90b8f3acb7
2 changed files with 6 additions and 6 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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 }}
|
||||
`
|
||||
|
|
6
cobra/cmd/testdata/root.go.golden
vendored
6
cobra/cmd/testdata/root.go.golden
vendored
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue