Propagate cancellation and preserve resumable state

This commit is contained in:
2026-11-20 05:53:49 +00:00
parent a6c6f1e4ab
commit c7a5ff316d
21 changed files with 356 additions and 27 deletions

View File

@@ -3,6 +3,8 @@ package main
import (
"context"
"os"
"os/signal"
"syscall"
"go.maximumdirect.net/commandkit"
@@ -10,6 +12,11 @@ import (
)
func main() {
outcome := app.Execute(context.Background(), os.Args[1:], commandkit.Streams{Out: os.Stdout, Err: os.Stderr})
os.Exit(outcome.Status)
os.Exit(runProcess(os.Args[1:], commandkit.Streams{Out: os.Stdout, Err: os.Stderr}, app.Execute))
}
func runProcess(args []string, streams commandkit.Streams, execute func(context.Context, []string, commandkit.Streams) commandkit.Outcome) int {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
return execute(ctx, args, streams).Status
}