From c0566977210ddba7db46b91dc4080429e45b253f Mon Sep 17 00:00:00 2001 From: MDietermann Date: Tue, 14 Apr 2026 21:56:23 +0200 Subject: [PATCH] feat(fonts): implement PlanForce to reinstall all fonts via yay --- internal/modules/fonts/fonts.go | 18 ++++++++++++++++-- internal/modules/fonts/fonts_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/internal/modules/fonts/fonts.go b/internal/modules/fonts/fonts.go index f2f3b18..978c626 100644 --- a/internal/modules/fonts/fonts.go +++ b/internal/modules/fonts/fonts.go @@ -3,7 +3,6 @@ package fonts import ( "context" - "errors" "fmt" "strings" @@ -83,5 +82,20 @@ func (m Module) Verify(ctx context.Context) error { } func (m Module) PlanForce(ctx context.Context) (module.Plan, error) { - return module.Plan{}, errors.New("PlanForce not implemented") + if len(m.fonts) == 0 { + return module.Plan{}, nil + } + fonts := append([]string{}, m.fonts...) + return module.Plan{Actions: []module.Action{ + { + Description: "ensure yay installed", + Kind: module.ActionPackageInstall, + Exec: func(ctx context.Context) error { return m.aur.EnsureInstalled(ctx) }, + }, + { + Description: "yay -S (force) " + strings.Join(fonts, ", "), + Kind: module.ActionPackageInstall, + Exec: func(ctx context.Context) error { return m.aur.Reinstall(ctx, fonts) }, + }, + }}, nil } diff --git a/internal/modules/fonts/fonts_test.go b/internal/modules/fonts/fonts_test.go index 78761af..0d917df 100644 --- a/internal/modules/fonts/fonts_test.go +++ b/internal/modules/fonts/fonts_test.go @@ -69,4 +69,31 @@ func TestFontsDetectPresentNoActions(t *testing.T) { } } +func TestPlanForceReinstallsAllFonts(t *testing.T) { + r := &fakeRunner{installed: map[string]bool{"yay": true, "ttf-jetbrains-mono-nerd": true}} + m := New([]string{"ttf-jetbrains-mono-nerd"}, platform.NewPacman(r), platform.NewYay(r)) + plan, err := m.PlanForce(context.Background()) + if err != nil { + t.Fatalf("PlanForce: %v", err) + } + if plan.IsEmpty() { + t.Fatal("force plan must not be empty") + } + for _, a := range plan.Actions { + if err := a.Exec(context.Background()); err != nil { + t.Fatalf("Exec: %v", err) + } + } + sawReinstall := false + for _, c := range r.runCalls { + // yay -S --noconfirm ... (no --needed) + if len(c) >= 3 && c[0] == "yay" && c[1] == "-S" && c[2] == "--noconfirm" { + sawReinstall = true + } + } + if !sawReinstall { + t.Fatalf("no yay reinstall (-S --noconfirm, no --needed) call; calls=%v", r.runCalls) + } +} + var _ module.Module = Module{}