Skip to content

Commit

Permalink
fix: give priority to new API for when getOut()
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarreira committed Oct 2, 2023
1 parent 2f70b7c commit e80bdb9
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (c *Command) OutOrStdout() io.Writer {
// OutOrStderr returns output to stderr.
// Deprecated: Use OutOrStdout or ErrOrStderr instead
func (c *Command) OutOrStderr() io.Writer {
return c.getOutFallbackToErr(os.Stderr)
return c.getErrOrLegacyOutFallbackToStderr()
}

// ErrOrStderr returns output to stderr
Expand All @@ -411,12 +411,12 @@ func (c *Command) InOrStdin() io.Reader {
}

func (c *Command) getOut(def io.Writer) io.Writer {
if c.legacyOutWriter != nil {
return c.legacyOutWriter
}
if c.outStreamWriter != nil {
return c.outStreamWriter
}
if c.legacyOutWriter != nil {
return c.legacyOutWriter
}
if c.HasParent() {
return c.parent.getOut(def)
}
Expand All @@ -436,20 +436,20 @@ func (c *Command) getErr(def io.Writer) io.Writer {
return def
}

// getOutFallbackToErr should only be used inside OutOrStderr.
// getErrOrLegacyOutFallbackToStderr should only be used inside OutOrStderr.
// Deprecated: this function exists to allow for backwards compatibility only
// (see https://github.com/spf13/cobra/issues/1708)
func (c *Command) getOutFallbackToErr(def io.Writer) io.Writer {
if c.legacyOutWriter != nil {
return c.legacyOutWriter
}
func (c *Command) getErrOrLegacyOutFallbackToStderr() io.Writer {
if c.errStreamWriter != nil {
return c.errStreamWriter
}
if c.legacyOutWriter != nil {
return c.legacyOutWriter
}
if c.HasParent() {
return c.parent.getOutFallbackToErr(def)
return c.parent.getErrOrLegacyOutFallbackToStderr()
}
return def
return os.Stderr
}

func (c *Command) getIn(def io.Reader) io.Reader {
Expand Down

0 comments on commit e80bdb9

Please sign in to comment.