From 22b6dbaad3915cb2c090ef08ea91d4682c7f65d1 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 31 Mar 2020 10:43:36 -0400 Subject: [PATCH] Set App.ErrWriter in App.Setup() - Defaults to os.Stderr - Remove the App.errWriter() function since it is no longer needed --- app.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/app.go b/app.go index eb68feb..9baca25 100644 --- a/app.go +++ b/app.go @@ -163,6 +163,10 @@ func (a *App) Setup() { a.Writer = os.Stdout } + if a.ErrWriter == nil { + a.ErrWriter = os.Stderr + } + var newCommands []*Command for _, c := range a.Commands { @@ -196,10 +200,6 @@ func (a *App) Setup() { if a.Metadata == nil { a.Metadata = make(map[string]interface{}) } - - if a.Writer == nil { - a.Writer = os.Stdout - } } func (a *App) newFlagSet() (*flag.FlagSet, error) { @@ -326,7 +326,7 @@ func (a *App) RunContext(ctx context.Context, arguments []string) (err error) { // code in the cli.ExitCoder func (a *App) RunAndExitOnError() { if err := a.Run(os.Args); err != nil { - _, _ = fmt.Fprintln(a.errWriter(), err) + _, _ = fmt.Fprintln(a.ErrWriter, err) OsExiter(1) } } @@ -480,15 +480,6 @@ func (a *App) VisibleFlags() []Flag { return visibleFlags(a.Flags) } -func (a *App) errWriter() io.Writer { - // When the app ErrWriter is nil use the package level one. - if a.ErrWriter == nil { - return ErrWriter - } - - return a.ErrWriter -} - func (a *App) appendFlag(fl Flag) { if !hasFlag(a.Flags, fl) { a.Flags = append(a.Flags, fl)