Skip to content

Commit

Permalink
fix: FTL truncating output (#2909)
Browse files Browse the repository at this point in the history
This fixes the most common cases of this, but it still could happen if
os.Exit is called elsewhere.

Fixes #2866
  • Loading branch information
stuartwdouglas authored Oct 1, 2024
1 parent c240d36 commit 69c8505
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions frontend/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -79,13 +80,14 @@ var cli CLI

func main() {
ctx, cancel := context.WithCancel(context.Background())

app := createKongApplication(&cli)
csm := &currentStatusManager{}
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()
}
Expand Down Expand Up @@ -137,7 +139,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`),
Expand All @@ -158,7 +160,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
}

Expand Down Expand Up @@ -202,3 +210,7 @@ func makeBindContext(projectConfig projectconfig.Config, logger *log.Logger, can
}
return bindContext
}

type currentStatusManager struct {
statusManager optional.Option[terminal.StatusManager]
}

0 comments on commit 69c8505

Please sign in to comment.