From 58a95a1f68d51b30a142615a34d2e0514765aabe Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Mon, 30 Sep 2024 09:54:01 +1000 Subject: [PATCH] fix: FTL truncating output This fixes the most common cases of this, but it still could happen if os.Exit is called elsewhere. Fixes #2866 --- frontend/cli/main.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/frontend/cli/main.go b/frontend/cli/main.go index 5f74d69960..acb71ed561 100644 --- a/frontend/cli/main.go +++ b/frontend/cli/main.go @@ -13,6 +13,7 @@ import ( "github.com/alecthomas/kong" kongtoml "github.com/alecthomas/kong-toml" + "github.com/alecthomas/types/optional" kongcompletion "github.com/jotaen/kong-completion" "github.com/TBD54566975/ftl" @@ -77,13 +78,14 @@ var cli CLI func main() { ctx, cancel := context.WithCancel(context.Background()) - - app := createKongApplication(&cli) + csm := ¤tStatusManager{} + app := createKongApplication(&cli, csm) kctx, err := app.Parse(os.Args[1:]) app.FatalIfErrorf(err) if !cli.Plain { sm := terminal.NewStatusManager(ctx) + csm.statusManager = optional.Some(sm) ctx = sm.IntoContext(ctx) defer sm.Close() } @@ -135,7 +137,7 @@ func main() { kctx.FatalIfErrorf(err) } -func createKongApplication(cli any) *kong.Kong { +func createKongApplication(cli any, csm *currentStatusManager) *kong.Kong { gitRoot, _ := internal.GitRoot(".").Get() app := kong.Must(cli, kong.Description(`FTL - Towards a 𝝺-calculus for large-scale systems`), @@ -156,7 +158,13 @@ func createKongApplication(cli any) *kong.Kong { "numcpu": strconv.Itoa(runtime.NumCPU()), "gitroot": gitRoot, }, - ) + kong.Exit(func(code int) { + if sm, ok := csm.statusManager.Get(); ok { + sm.Close() + } + os.Exit(code) + }, + )) return app } @@ -196,3 +204,7 @@ func makeBindContext(projectConfig projectconfig.Config, logger *log.Logger, can } return bindContext } + +type currentStatusManager struct { + statusManager optional.Option[terminal.StatusManager] +}