feat(module): add PlanForce to Module interface with stubs

This commit is contained in:
MDietermann
2026-04-14 21:49:09 +02:00
parent e6e12ab5fd
commit d525646f3a
19 changed files with 96 additions and 0 deletions

View File

@@ -31,6 +31,12 @@ func (s scriptedModule) Plan(ctx context.Context, _ module.State) (module.Plan,
} }
return module.Plan{}, nil return module.Plan{}, nil
} }
func (s scriptedModule) PlanForce(ctx context.Context) (module.Plan, error) {
if s.plan != nil {
return s.plan()
}
return module.Plan{}, nil
}
func (s scriptedModule) Apply(ctx context.Context, _ module.Plan, _ module.Reporter) error { func (s scriptedModule) Apply(ctx context.Context, _ module.Plan, _ module.Reporter) error {
if s.apply != nil { if s.apply != nil {
return s.apply() return s.apply()

View File

@@ -49,6 +49,12 @@ type Module interface {
Meta() Meta Meta() Meta
Detect(ctx context.Context) (State, error) Detect(ctx context.Context) (State, error)
Plan(ctx context.Context, current State) (Plan, error) Plan(ctx context.Context, current State) (Plan, error)
// PlanForce returns a plan that reapplies the module unconditionally,
// ignoring current detected state. Used by `archduino install --force`.
// Implementations should produce a plan equivalent to a from-scratch
// install — reinstall packages without pacman's --needed guard and
// rewrite managed config files.
PlanForce(ctx context.Context) (Plan, error)
Apply(ctx context.Context, plan Plan, r Reporter) error Apply(ctx context.Context, plan Plan, r Reporter) error
Verify(ctx context.Context) error Verify(ctx context.Context) error
} }

View File

@@ -13,6 +13,7 @@ type fakeModule struct {
func (f fakeModule) Meta() Meta { return Meta{ID: f.id, Name: f.id, Deps: f.deps} } func (f fakeModule) Meta() Meta { return Meta{ID: f.id, Name: f.id, Deps: f.deps} }
func (f fakeModule) Detect(context.Context) (State, error) { return nil, nil } func (f fakeModule) Detect(context.Context) (State, error) { return nil, nil }
func (f fakeModule) Plan(context.Context, State) (Plan, error) { return Plan{}, nil } func (f fakeModule) Plan(context.Context, State) (Plan, error) { return Plan{}, nil }
func (f fakeModule) PlanForce(context.Context) (Plan, error) { return Plan{}, nil }
func (f fakeModule) Apply(context.Context, Plan, Reporter) error { return nil } func (f fakeModule) Apply(context.Context, Plan, Reporter) error { return nil }
func (f fakeModule) Verify(context.Context) error { return nil } func (f fakeModule) Verify(context.Context) error { return nil }

View File

@@ -4,6 +4,7 @@ package arduinocli
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@@ -136,3 +137,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -3,6 +3,7 @@ package fonts
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
@@ -80,3 +81,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -3,6 +3,7 @@ package gittools
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
@@ -72,3 +73,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -4,6 +4,7 @@ package hello
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@@ -96,3 +97,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -6,6 +6,7 @@ package neovim
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"embed" "embed"
"fmt" "fmt"
"os" "os"
@@ -461,3 +462,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -3,6 +3,7 @@ package packages
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
@@ -72,3 +73,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -5,6 +5,7 @@ package renode
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"embed" "embed"
"fmt" "fmt"
"os" "os"
@@ -185,3 +186,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -3,6 +3,7 @@ package shellconfig
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@@ -88,3 +89,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -3,6 +3,7 @@ package starship
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
@@ -72,3 +73,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -4,6 +4,7 @@ package themes
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"io/fs" "io/fs"
"os" "os"
@@ -113,3 +114,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -3,6 +3,7 @@ package yazi
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strings" "strings"
@@ -72,3 +73,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -3,6 +3,7 @@ package zellij
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@@ -108,3 +109,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -3,6 +3,7 @@ package zsh
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@@ -130,3 +131,7 @@ func (m Module) Verify(ctx context.Context) error {
} }
return nil return nil
} }
func (m Module) PlanForce(ctx context.Context) (module.Plan, error) {
return module.Plan{}, errors.New("PlanForce not implemented")
}

View File

@@ -19,6 +19,9 @@ func (c convergedModule) Detect(context.Context) (module.State, error) { return
func (c convergedModule) Plan(context.Context, module.State) (module.Plan, error) { func (c convergedModule) Plan(context.Context, module.State) (module.Plan, error) {
return module.Plan{}, nil return module.Plan{}, nil
} }
func (c convergedModule) PlanForce(context.Context) (module.Plan, error) {
return module.Plan{}, nil
}
func (c convergedModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil } func (c convergedModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil }
func (c convergedModule) Verify(context.Context) error { return nil } func (c convergedModule) Verify(context.Context) error { return nil }
@@ -29,6 +32,9 @@ func (p pendingModule) Detect(context.Context) (module.State, error) { return ni
func (p pendingModule) Plan(context.Context, module.State) (module.Plan, error) { func (p pendingModule) Plan(context.Context, module.State) (module.Plan, error) {
return module.Plan{Actions: []module.Action{{Description: "do a thing"}}}, nil return module.Plan{Actions: []module.Action{{Description: "do a thing"}}}, nil
} }
func (p pendingModule) PlanForce(context.Context) (module.Plan, error) {
return module.Plan{Actions: []module.Action{{Description: "do a thing"}}}, nil
}
func (p pendingModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil } func (p pendingModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil }
func (p pendingModule) Verify(context.Context) error { return nil } func (p pendingModule) Verify(context.Context) error { return nil }
@@ -41,6 +47,9 @@ func (d detectFailModule) Detect(context.Context) (module.State, error) {
func (d detectFailModule) Plan(context.Context, module.State) (module.Plan, error) { func (d detectFailModule) Plan(context.Context, module.State) (module.Plan, error) {
return module.Plan{}, nil return module.Plan{}, nil
} }
func (d detectFailModule) PlanForce(context.Context) (module.Plan, error) {
return module.Plan{}, nil
}
func (d detectFailModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil } func (d detectFailModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil }
func (d detectFailModule) Verify(context.Context) error { return nil } func (d detectFailModule) Verify(context.Context) error { return nil }

View File

@@ -18,6 +18,9 @@ func (f fakeModule) Detect(context.Context) (module.State, error) { return nil,
func (f fakeModule) Plan(context.Context, module.State) (module.Plan, error) { func (f fakeModule) Plan(context.Context, module.State) (module.Plan, error) {
return module.Plan{}, nil return module.Plan{}, nil
} }
func (f fakeModule) PlanForce(context.Context) (module.Plan, error) {
return module.Plan{}, nil
}
func (f fakeModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil } func (f fakeModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil }
func (f fakeModule) Verify(context.Context) error { return nil } func (f fakeModule) Verify(context.Context) error { return nil }

View File

@@ -119,6 +119,12 @@ func (c countingModule) Plan(context.Context, module.State) (module.Plan, error)
} }
return module.Plan{}, nil return module.Plan{}, nil
} }
func (c countingModule) PlanForce(context.Context) (module.Plan, error) {
if c.onPlan != nil {
c.onPlan()
}
return module.Plan{}, nil
}
func (c countingModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil } func (c countingModule) Apply(context.Context, module.Plan, module.Reporter) error { return nil }
func (c countingModule) Verify(context.Context) error { return nil } func (c countingModule) Verify(context.Context) error { return nil }