feat(cmd): wire TUI wizard and dashboard into install subcommand

This commit is contained in:
MDietermann
2026-04-13 22:13:52 +02:00
parent 7baf0fceaa
commit 341250d8f4

View File

@@ -15,6 +15,9 @@ import (
"github.com/MDietermann/ArduinoArchSetup/internal/platform"
"github.com/MDietermann/ArduinoArchSetup/internal/privilege"
"github.com/MDietermann/ArduinoArchSetup/internal/state"
"github.com/MDietermann/ArduinoArchSetup/internal/tui"
"github.com/MDietermann/ArduinoArchSetup/internal/tui/dashboard"
"github.com/MDietermann/ArduinoArchSetup/internal/tui/wizard"
)
var version = "dev"
@@ -95,24 +98,53 @@ func newInstallCmd() *cobra.Command {
defer k.Stop()
}
reporter := engine.NewPlainReporter(os.Stdout)
// When the user did NOT opt out of TUI (the default), note that
// the TUI isn't implemented yet and we're falling back to plain
// output. Plan 2 wires up Bubble Tea here; at that point this
// branch becomes the TUI setup and the PlainReporter above moves
// inside the `noTUI` branch.
if !noTUI {
fmt.Fprintln(os.Stdout, "(TUI not yet implemented — using plain output)")
}
started := time.Now().UTC()
sum, err := engine.Run(ctx, Registry, engine.RunOptions{
var (
sum engine.Summary
runErr error
)
if noTUI || dryRun {
// Plain-output path: preserve the Plan 1 behaviour. Dry-run
// always uses plain output because the dashboard has nothing
// to animate when no Apply happens.
reporter := engine.NewPlainReporter(os.Stdout)
sum, runErr = engine.Run(ctx, Registry, engine.RunOptions{
Selected: selected,
DryRun: dryRun,
HaltOnError: halt,
Reporter: reporter,
})
} else {
// TUI path: wizard → dashboard. If the user does not confirm,
// we exit cleanly with a zero-summary and no error.
initial := tui.NewWizardState(cfg, Registry)
// Pre-filter the wizard's module list by --only/--skip so the
// user cannot accidentally widen selection in the TUI beyond
// what they asked for on the CLI.
if len(selected) < len(initial.Modules) {
wanted := map[string]bool{}
for _, id := range selected {
wanted[id] = true
}
for i := range initial.Modules {
initial.Modules[i].Selected = wanted[initial.Modules[i].ID]
}
}
finalState, confirmed, werr := wizard.Run(ctx, Registry, initial)
if werr != nil {
return werr
}
if !confirmed {
fmt.Fprintln(os.Stdout, "installation cancelled")
return nil
}
sum, runErr = dashboard.Run(ctx, Registry, finalState, halt)
}
ended := time.Now().UTC()
err = runErr
if err != nil {
return err
}