fix(summer): pass the app binary's exit code through and print its error once

- bonfire.WithExitCode (additive) makes an error carry the exit code
  bonfire.Execute returns; a code outside 1..255 gives 1
- runAppCmd, factored out of runAppBinary, returns
  Reported(WithExitCode(err, code)) when the binary exited with a code, so
  summer prints no second error block; a binary killed by a signal keeps
  summer's block and exit 1
- README, console introduction and upgrading notes say so (CR-02)
This commit is contained in:
Jakub Zych
2026-10-22 02:17:09 +02:00
parent d151a252c5
commit 323413c741
8 changed files with 165 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ package bonfire
import (
"context"
"errors"
"io"
"os"
"slices"
@@ -23,11 +24,11 @@ const (
)
// Execute runs root with args and returns the process exit code: ExitOK,
// ExitFailure, or ExitUsage for usage errors. With no command word in args
// (only global options, -h or --help) it prints the command list. Errors are
// rendered on the root's error stream by RenderError through fang's error
// handler; fang is used without its version flag, man page and completion
// commands.
// ExitFailure, ExitUsage for usage errors, or the code an error carries
// through WithExitCode. With no command word in args (only global options,
// -h or --help) it prints the command list. Errors are rendered on the
// root's error stream by RenderError through fang's error handler; fang is
// used without its version flag, man page and completion commands.
func Execute(ctx context.Context, root *cobra.Command, args []string) int {
if ctx == nil {
ctx = context.Background()
@@ -73,9 +74,15 @@ func Fail(w io.Writer, name string, err error, g Globals) int {
}
func exitCode(err error) int {
var carrier *exitCodeError
switch {
case err == nil:
return ExitOK
case errors.As(err, &carrier):
if carrier.code < 1 || carrier.code > 255 {
return ExitFailure
}
return carrier.code
case isUsage(err):
return ExitUsage
default: