feat(cmd): register all Plan 3a modules in install command
Replace the init()-time hello toy-module registration with a buildRegistry(cfg) helper called from the install RunE that wires the ten Plan 3a modules (packages, gittools, starship, yazi, zsh, fonts, zellij, themes, arduinocli, shellconfig) against a shared ExecRunner, Pacman, Yay, and GitClient.
This commit is contained in:
@@ -13,7 +13,16 @@ import (
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/config"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/engine"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/module"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/hello"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/arduinocli"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/fonts"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/gittools"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/packages"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/shellconfig"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/starship"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/themes"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/yazi"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/zellij"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/modules/zsh"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/platform"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/privilege"
|
||||
"github.com/MDietermann/ArduinoArchSetup/internal/state"
|
||||
@@ -24,14 +33,35 @@ import (
|
||||
|
||||
var version = "dev"
|
||||
|
||||
// Registry is the global module registry. Tasks in Plan 3 will register
|
||||
// real modules into it via init(). Task 12 registers the hello toy module.
|
||||
var Registry = module.NewRegistry()
|
||||
// buildRegistry constructs a module registry populated with all Plan 3a
|
||||
// modules, wired against the provided config and platform dependencies.
|
||||
// It replaces the earlier init()-time hello-module registration now that
|
||||
// the real modules need runtime config to be instantiated.
|
||||
func buildRegistry(cfg config.Config) (*module.Registry, error) {
|
||||
reg := module.NewRegistry()
|
||||
runner := platform.ExecRunner{}
|
||||
pm := platform.NewPacman(runner)
|
||||
yay := platform.NewYay(runner)
|
||||
git := platform.GitClient{Runner: runner}
|
||||
|
||||
func init() {
|
||||
if err := Registry.Register(hello.Module{}); err != nil {
|
||||
panic(err)
|
||||
mods := []module.Module{
|
||||
packages.New(cfg.Packages.Base, pm),
|
||||
gittools.New([]string{"lazygit"}, pm),
|
||||
starship.New([]string{"starship"}, pm),
|
||||
yazi.New([]string{"yazi"}, pm),
|
||||
zsh.New(cfg.Zsh, pm, git),
|
||||
fonts.New(cfg.Fonts, pm, yay),
|
||||
zellij.New(cfg.Zellij, pm),
|
||||
themes.New(cfg.Themes),
|
||||
arduinocli.New(cfg.ArduinoCLI, runner),
|
||||
shellconfig.New(cfg.ShellConfig),
|
||||
}
|
||||
for _, m := range mods {
|
||||
if err := reg.Register(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return reg, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -92,7 +122,12 @@ func newInstallCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
selected, err := resolveSelection(Registry, cfg, only, skip)
|
||||
reg, err := buildRegistry(cfg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("build registry: %w", err)
|
||||
}
|
||||
|
||||
selected, err := resolveSelection(reg, cfg, only, skip)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -117,7 +152,7 @@ func newInstallCmd() *cobra.Command {
|
||||
// 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{
|
||||
sum, runErr = engine.Run(ctx, reg, engine.RunOptions{
|
||||
Selected: selected,
|
||||
DryRun: dryRun,
|
||||
HaltOnError: halt,
|
||||
@@ -126,7 +161,7 @@ func newInstallCmd() *cobra.Command {
|
||||
} 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)
|
||||
initial := tui.NewWizardState(cfg, reg)
|
||||
// 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.
|
||||
@@ -140,7 +175,7 @@ func newInstallCmd() *cobra.Command {
|
||||
}
|
||||
}
|
||||
|
||||
finalState, confirmed, werr := wizard.Run(ctx, Registry, initial)
|
||||
finalState, confirmed, werr := wizard.Run(ctx, reg, initial)
|
||||
if werr != nil {
|
||||
return werr
|
||||
}
|
||||
@@ -149,7 +184,7 @@ func newInstallCmd() *cobra.Command {
|
||||
return nil
|
||||
}
|
||||
// Either the CLI flag or the wizard toggle can force halt-on-error.
|
||||
sum, runErr = dashboard.Run(ctx, Registry, finalState, halt || finalState.HaltOnError)
|
||||
sum, runErr = dashboard.Run(ctx, reg, finalState, halt || finalState.HaltOnError)
|
||||
}
|
||||
|
||||
ended := time.Now().UTC()
|
||||
|
||||
Reference in New Issue
Block a user