summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-05 10:48:52 +0300
committerPaul Buetow <paul@buetow.org>2026-07-05 10:48:52 +0300
commit1b97ed3ca759a530585a520c8edd01e26bdee582 (patch)
tree02cc4abd4374a515a2ac9df592144839bbc148b4
parent7fdcb5ed7639508e05c9a3851704cf1de9f4476a (diff)
initial work for a central applier algo
-rw-r--r--README.md2
-rw-r--r--internal/resource/dir/dir.go6
-rw-r--r--internal/resource/file/file.go20
-rw-r--r--internal/resource/link/link.go14
-rw-r--r--internal/resource/resource.go14
5 files changed, 36 insertions, 20 deletions
diff --git a/README.md b/README.md
index fd29ce4..a7e2992 100644
--- a/README.md
+++ b/README.md
@@ -3,5 +3,3 @@
<img src="assets/logo-light.svg" alt="Gonf logo" width="140">
Pure-Go syntax KISS configuration management system for personal use.
-
-Mainly coded by hand, with some minor help from AI.
diff --git a/internal/resource/dir/dir.go b/internal/resource/dir/dir.go
index 8be4395..047a591 100644
--- a/internal/resource/dir/dir.go
+++ b/internal/resource/dir/dir.go
@@ -12,6 +12,7 @@ import (
)
type Dir struct {
+ resource resource.Resource
path string
source string
user string
@@ -192,13 +193,14 @@ func Have(path string, opts ...opt.Option) resource.Resource {
log.Fatalf("failed to apply directory resource %s: %v", path, err)
}
- res := resource.Register("Directory", d.path)
+ d.resource = resource.Register("Directory", d.path,
+ resource.ApplierFunc(func() error { return d.apply() }))
if err := d.apply(); err != nil {
log.Fatalf("failed to apply directory resource %s: %v", path, err)
}
- return res
+ return d.resource
}
func Absent(path string, opts ...opt.Option) resource.Resource {
diff --git a/internal/resource/file/file.go b/internal/resource/file/file.go
index 6395403..5a2453e 100644
--- a/internal/resource/file/file.go
+++ b/internal/resource/file/file.go
@@ -15,13 +15,14 @@ import (
)
type File struct {
- path string
- content string
- source string // bare path, no "source://" prefix
- user string
- group string
- mode os.FileMode
- absent bool
+ resource resource.Resource
+ path string
+ content string
+ source string // bare path, no "source://" prefix
+ user string
+ group string
+ mode os.FileMode
+ absent bool
}
// SetContent implements opt.Contented. Setting literal content clears any
@@ -223,13 +224,14 @@ func Have(path string, opts ...opt.Option) resource.Resource {
log.Fatalf("failed to apply file resource %s: %v", path, err)
}
- res := resource.Register("File", f.targetPath())
+ f.resource = resource.Register("File", f.targetPath(),
+ resource.ApplierFunc(func() error { return f.apply() }))
if err := f.apply(); err != nil {
log.Fatalf("failed to apply file resource %s: %v", path, err)
}
- return res
+ return f.resource
}
func Absent(path string, opts ...opt.Option) resource.Resource {
diff --git a/internal/resource/link/link.go b/internal/resource/link/link.go
index f9c6c8d..5f8e345 100644
--- a/internal/resource/link/link.go
+++ b/internal/resource/link/link.go
@@ -18,10 +18,11 @@ const (
)
type Link struct {
- path string
- target string
- kind kind
- absent bool
+ resource resource.Resource
+ path string
+ target string
+ kind kind
+ absent bool
}
// SetSymlink implements opt.Linkable.
@@ -87,13 +88,14 @@ func Ensure(path string, opts ...opt.Option) error {
func Have(path string, opts ...opt.Option) resource.Resource {
l := build(path, opts...)
- res := resource.Register(l.resourceType(), l.path)
+ l.resource = resource.Register(l.resourceType(), l.path,
+ resource.ApplierFunc(func() error { return l.apply() }))
if err := l.apply(); err != nil {
log.Fatalf("failed to apply link resource %s: %v", path, err)
}
- return res
+ return l.resource
}
func Absent(path string, opts ...opt.Option) resource.Resource {
diff --git a/internal/resource/resource.go b/internal/resource/resource.go
index f7951c3..4e72485 100644
--- a/internal/resource/resource.go
+++ b/internal/resource/resource.go
@@ -5,16 +5,28 @@ import (
"log"
)
+type Applier interface {
+ Apply() error
+}
+
+type ApplierFunc func() error
+
+func (f ApplierFunc) Apply() error {
+ return f()
+}
+
type Resource struct {
Type string
Name string
+ Apply Applier
dependsOn map[string]struct{}
}
-func Register(type_, name string) Resource {
+func Register(type_, name string, apply Applier) Resource {
r := Resource{
Type: type_,
Name: name,
+ Apply: apply,
dependsOn: make(map[string]struct{}),
}