- tui/doc.go: remove teatest blank import (test harness in prod binary) - cmd: honor wizard HaltOnError toggle in addition to --halt-on-error flag - cmd: wire SIGINT/SIGTERM to root context via signal.NotifyContext - dashboard/run: derive engine context and cancel on tea.Program exit so the engine goroutine does not outlive Run
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
tea "github.com/charmbracelet/bubbletea"
|
|
|
|
"github.com/MDietermann/ArduinoArchSetup/internal/engine"
|
|
"github.com/MDietermann/ArduinoArchSetup/internal/module"
|
|
"github.com/MDietermann/ArduinoArchSetup/internal/tui"
|
|
)
|
|
|
|
// Run displays the dashboard while engine.Run executes the selected modules.
|
|
// Returns the engine summary (for writeState) and the top-level error, if any.
|
|
func Run(ctx context.Context, reg *module.Registry, state tui.WizardState, halt bool) (engine.Summary, error) {
|
|
selected := state.SelectedIDs()
|
|
nameByID := make(map[string]string, len(state.Modules))
|
|
for _, m := range state.Modules {
|
|
nameByID[m.ID] = m.Name
|
|
}
|
|
|
|
m := NewModel(selected, nameByID)
|
|
p := tea.NewProgram(m, tea.WithContext(ctx))
|
|
|
|
// Derived context so that when p.Run() returns (user pressed q, tea
|
|
// errored, parent ctx cancelled) the engine goroutine is cancelled
|
|
// too. Deferred cancel ensures no orphan goroutine outlives Run.
|
|
engineCtx, cancelEngine := context.WithCancel(ctx)
|
|
defer cancelEngine()
|
|
|
|
reporter := tui.NewTeaReporter(p)
|
|
|
|
go func() {
|
|
// TODO(plan-3): forward state.Parallelism once engine.RunOptions
|
|
// gains a Parallelism field and the engine supports concurrent Apply.
|
|
summary, err := engine.Run(engineCtx, reg, engine.RunOptions{
|
|
Selected: selected,
|
|
HaltOnError: halt,
|
|
Reporter: reporter,
|
|
})
|
|
p.Send(DoneMsg{Summary: summary, Err: err})
|
|
}()
|
|
|
|
if _, err := p.Run(); err != nil {
|
|
return engine.Summary{}, fmt.Errorf("tui run: %w", err)
|
|
}
|
|
|
|
var sum engine.Summary
|
|
if m.Summary() != nil {
|
|
sum = *m.Summary()
|
|
}
|
|
return sum, m.RunErr()
|
|
}
|