mirror of
https://github.com/spf13/cobra.git
synced 2024-12-19 10:05:07 -07:00
fix: give priority to new API for when getOut()
This commit is contained in:
parent
2f70b7caa3
commit
e80bdb9a8c
24
command.go
24
command.go
@ -397,7 +397,7 @@ func (c *Command) OutOrStdout() io.Writer {
|
|||||||
// OutOrStderr returns output to stderr.
|
// OutOrStderr returns output to stderr.
|
||||||
// Deprecated: Use OutOrStdout or ErrOrStderr instead
|
// Deprecated: Use OutOrStdout or ErrOrStderr instead
|
||||||
func (c *Command) OutOrStderr() io.Writer {
|
func (c *Command) OutOrStderr() io.Writer {
|
||||||
return c.getOutFallbackToErr(os.Stderr)
|
return c.getErrOrLegacyOutFallbackToStderr()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrOrStderr returns output to stderr
|
// ErrOrStderr returns output to stderr
|
||||||
@ -411,12 +411,12 @@ func (c *Command) InOrStdin() io.Reader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) getOut(def io.Writer) io.Writer {
|
func (c *Command) getOut(def io.Writer) io.Writer {
|
||||||
if c.legacyOutWriter != nil {
|
|
||||||
return c.legacyOutWriter
|
|
||||||
}
|
|
||||||
if c.outStreamWriter != nil {
|
if c.outStreamWriter != nil {
|
||||||
return c.outStreamWriter
|
return c.outStreamWriter
|
||||||
}
|
}
|
||||||
|
if c.legacyOutWriter != nil {
|
||||||
|
return c.legacyOutWriter
|
||||||
|
}
|
||||||
if c.HasParent() {
|
if c.HasParent() {
|
||||||
return c.parent.getOut(def)
|
return c.parent.getOut(def)
|
||||||
}
|
}
|
||||||
@ -436,20 +436,20 @@ func (c *Command) getErr(def io.Writer) io.Writer {
|
|||||||
return def
|
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
|
// Deprecated: this function exists to allow for backwards compatibility only
|
||||||
// (see https://github.com/spf13/cobra/issues/1708)
|
// (see https://github.com/spf13/cobra/issues/1708)
|
||||||
func (c *Command) getOutFallbackToErr(def io.Writer) io.Writer {
|
func (c *Command) getErrOrLegacyOutFallbackToStderr() io.Writer {
|
||||||
if c.legacyOutWriter != nil {
|
|
||||||
return c.legacyOutWriter
|
|
||||||
}
|
|
||||||
if c.errStreamWriter != nil {
|
if c.errStreamWriter != nil {
|
||||||
return c.errStreamWriter
|
return c.errStreamWriter
|
||||||
}
|
}
|
||||||
if c.HasParent() {
|
if c.legacyOutWriter != nil {
|
||||||
return c.parent.getOutFallbackToErr(def)
|
return c.legacyOutWriter
|
||||||
}
|
}
|
||||||
return def
|
if c.HasParent() {
|
||||||
|
return c.parent.getErrOrLegacyOutFallbackToStderr()
|
||||||
|
}
|
||||||
|
return os.Stderr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) getIn(def io.Reader) io.Reader {
|
func (c *Command) getIn(def io.Reader) io.Reader {
|
||||||
|
Loading…
Reference in New Issue
Block a user