fix(summer): send a delegate's stderr to the root's error writer through bonfire.ErrWriter (IN-13, quick-261028-rqd)
This commit is contained in:
@@ -3,6 +3,8 @@ package bonfire
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
tea "charm.land/bubbletea/v2"
|
||||
@@ -15,6 +17,7 @@ type consoleState interface {
|
||||
consoleGlobals() Globals
|
||||
consoleInteractive() bool
|
||||
consoleTerminal() bool
|
||||
consoleErrWriter() io.Writer
|
||||
}
|
||||
|
||||
func (c *console) consoleGlobals() Globals { return c.globals }
|
||||
@@ -23,6 +26,13 @@ func (c *console) consoleInteractive() bool { return c.canPrompt() }
|
||||
|
||||
func (c *console) consoleTerminal() bool { return c.tty }
|
||||
|
||||
func (c *console) consoleErrWriter() io.Writer {
|
||||
if c.errStream != nil {
|
||||
return c.errStream
|
||||
}
|
||||
return c.err
|
||||
}
|
||||
|
||||
// GlobalsOf returns the global options of the command out belongs to, or
|
||||
// the zero Globals when out is not a bonfire console.
|
||||
func GlobalsOf(out Output) Globals {
|
||||
@@ -63,6 +73,21 @@ func IsTerminal(out Output) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ErrWriter returns the stream the root's error block goes to for the
|
||||
// command out belongs to: os.Stderr for a root built by NewRoot on
|
||||
// os.Stdout, the error writer given to NewRootIO or NewOutput (stdout when
|
||||
// NewOutput gets none), and os.Stderr for an Output that is not a bonfire
|
||||
// console. summer sends an app binary's stderr there, so a root built on
|
||||
// buffers captures it while the real summer keeps it on stderr.
|
||||
func ErrWriter(out Output) io.Writer {
|
||||
if s, ok := out.(consoleState); ok {
|
||||
if w := s.consoleErrWriter(); w != nil {
|
||||
return w
|
||||
}
|
||||
}
|
||||
return os.Stderr
|
||||
}
|
||||
|
||||
// Detail is one line of a Details block: a label and its value. Warn
|
||||
// prints the value in the warning color.
|
||||
type Detail struct {
|
||||
|
||||
Reference in New Issue
Block a user