fix(summer): give delegated commands the terminal and keep their stderr apart

- appStreams hands the app binary summer's own stdout and stderr on a
  terminal, so it asks the production question, prints styled summaries
  and animates its widgets
- off a terminal the binary's stdout goes through summer's Output and its
  stderr to summer's stderr, so --json and -q output carry no log lines
- newAppCmd (unexported) takes the two writers; docs say the streams stay
  apart (CR-03)
This commit is contained in:
Jakub Zych
2026-10-22 02:19:01 +02:00
parent 323413c741
commit 9c89705747
4 changed files with 83 additions and 12 deletions

View File

@@ -141,7 +141,22 @@ func runAppBinary(ctx context.Context, argv []string, out bonfire.Output) error
return fmt.Errorf("summer: refusing to recurse into %s", bin)
}
}
return runAppCmd(newAppCmd(ctx, bin, appDir, argv, out), argv)
stdout, stderr := appStreams(out, bonfire.IsTerminal(out))
return runAppCmd(newAppCmd(ctx, bin, appDir, argv, stdout, stderr), argv)
}
// appStreams picks the app binary's stdout and stderr. On a terminal
// (terminal is bonfire.IsTerminal(out)) the binary gets summer's own
// streams, so it sees the terminal: it asks the production question, prints
// styled summaries and animates its widgets. Otherwise its stdout goes
// through out (tests and bonfire.Call roots capture it) and its stderr to
// summer's stderr, so log lines and error blocks never mix into data such
// as --json output.
func appStreams(out bonfire.Output, terminal bool) (stdout, stderr io.Writer) {
if terminal {
return os.Stdout, os.Stderr
}
return out, os.Stderr
}
// runAppCmd runs cmd, the app binary started with argv, forwarding SIGINT
@@ -170,15 +185,16 @@ func runAppCmd(cmd *exec.Cmd, argv []string) error {
// timeout of serve and the workers, so they finish a graceful shutdown.
const appShutdownGrace = 15 * time.Second
// newAppCmd builds the command that runs the app binary bin with argv in dir.
// The child inherits summer's stdin, so the hidden password prompts of
// admin:create and admin:reset-password read from the terminal. Cancelling
// ctx sends SIGTERM, and the child is killed only after appShutdownGrace.
func newAppCmd(ctx context.Context, bin, dir string, argv []string, out io.Writer) *exec.Cmd {
// newAppCmd builds the command that runs the app binary bin with argv in
// dir, writing to stdout and stderr (see appStreams). The child inherits
// summer's stdin, so the hidden password prompts of admin:create and
// admin:reset-password read from the terminal. Cancelling ctx sends
// SIGTERM, and the child is killed only after appShutdownGrace.
func newAppCmd(ctx context.Context, bin, dir string, argv []string, stdout, stderr io.Writer) *exec.Cmd {
cmd := exec.CommandContext(ctx, bin, argv...)
cmd.Dir = dir
cmd.Stdout = out
cmd.Stderr = out
cmd.Stdout = stdout
cmd.Stderr = stderr
cmd.Stdin = os.Stdin
cmd.Env = os.Environ()
cmd.Cancel = func() error {