feat(fonts): implement PlanForce to reinstall all fonts via yay
This commit is contained in:
@@ -3,7 +3,6 @@ package fonts
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -83,5 +82,20 @@ func (m Module) Verify(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m Module) PlanForce(ctx context.Context) (module.Plan, 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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{}
|
var _ module.Module = Module{}
|
||||||
|
|||||||
Reference in New Issue
Block a user