summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-06 23:05:48 +0300
committerPaul Buetow <paul@buetow.org>2026-07-06 23:05:48 +0300
commit5600bedb927e291e2e78e6140de256e1a1d4475c (patch)
treeaf19c6b484135afed332a8e3fcda7e8ded5ac4b8
parentf7498c9ae626b9ab654fe6eb736e19c62cf5d38d (diff)
refactor
-rw-r--r--api/api.go15
-rw-r--r--api/options/option.go (renamed from api/option/option.go)2
-rw-r--r--api/resource.go17
-rw-r--r--examples/examples.go5
-rw-r--r--internal/resource/dir/dir.go2
-rw-r--r--internal/resource/dir/dir_test.go2
-rw-r--r--internal/resource/dir/source.go2
-rw-r--r--internal/resource/file/file.go2
-rw-r--r--internal/resource/file/file_test.go2
-rw-r--r--internal/resource/link/link.go2
-rw-r--r--internal/resource/link/link_test.go2
11 files changed, 34 insertions, 19 deletions
diff --git a/api/api.go b/api/api.go
index f4ec70e..ea30363 100644
--- a/api/api.go
+++ b/api/api.go
@@ -1,39 +1,38 @@
package api
import (
- "codeberg.org/snonux/gonf/api/option"
- "codeberg.org/snonux/gonf/internal/resource"
+ "codeberg.org/snonux/gonf/api/options"
"codeberg.org/snonux/gonf/internal/resource/dir"
"codeberg.org/snonux/gonf/internal/resource/file"
"codeberg.org/snonux/gonf/internal/resource/link"
)
// File creates a file resource.
-func File(path string, opts ...option.Option) resource.Resource {
+func File(path string, opts ...options.Option) Resource {
return file.Present(path, opts...)
}
// NoFile creates a file resource that is ensured to be absent.
-func NoFile(path string, opts ...option.Option) resource.Resource {
+func NoFile(path string, opts ...options.Option) Resource {
return file.Absent(path, opts...)
}
// Dir creates a directory resource.
-func Dir(path string, opts ...option.Option) resource.Resource {
+func Dir(path string, opts ...options.Option) Resource {
return dir.Present(path, opts...)
}
// NoDir creates a directory resource that is ensured to be absent.
-func NoDir(path string, opts ...option.Option) resource.Resource {
+func NoDir(path string, opts ...options.Option) Resource {
return dir.Absent(path, opts...)
}
// Link creates a link resource (symbolic or hard).
-func Link(path string, opts ...option.Option) resource.Resource {
+func Link(path string, opts ...options.Option) Resource {
return link.Present(path, opts...)
}
// NoLink creates a link resource that is ensured to be absent.
-func NoLink(path string, opts ...option.Option) resource.Resource {
+func NoLink(path string, opts ...options.Option) Resource {
return link.Absent(path, opts...)
}
diff --git a/api/option/option.go b/api/options/option.go
index b5d2531..1c757c4 100644
--- a/api/option/option.go
+++ b/api/options/option.go
@@ -1,6 +1,6 @@
// Package option provides interface-based, resource-agnostic configuration
// options shared by the file, dir, and link resource packages.
-package option
+package options
import (
"log"
diff --git a/api/resource.go b/api/resource.go
new file mode 100644
index 0000000..e254e1b
--- /dev/null
+++ b/api/resource.go
@@ -0,0 +1,17 @@
+package api
+
+import (
+ internal "codeberg.org/snonux/gonf/internal/resource"
+)
+
+// Resource represents a system resource managed by gonfs.
+// It is an interface to hide the internal implementation details
+// of the resource registry.
+type Resource interface {
+ ID() string
+ String() string
+}
+
+func Apply() error {
+ return internal.Apply()
+}
diff --git a/examples/examples.go b/examples/examples.go
index 1a1df0b..2168a40 100644
--- a/examples/examples.go
+++ b/examples/examples.go
@@ -4,8 +4,7 @@ import (
"os"
. "codeberg.org/snonux/gonf/api"
- . "codeberg.org/snonux/gonf/api/option"
- "codeberg.org/snonux/gonf/internal/resource"
+ . "codeberg.org/snonux/gonf/api/options"
)
func Run() error {
@@ -68,5 +67,5 @@ func Run() error {
_ = os.Link("/tmp/gonf_hello.txt", "/tmp/gonf_stale_hardlink")
Link("/tmp/gonf_stale_hardlink", IsAbsent())
- return resource.Apply()
+ return Apply()
}
diff --git a/internal/resource/dir/dir.go b/internal/resource/dir/dir.go
index 283cea9..94220b7 100644
--- a/internal/resource/dir/dir.go
+++ b/internal/resource/dir/dir.go
@@ -7,7 +7,7 @@ import (
"os/user"
"strconv"
- opt "codeberg.org/snonux/gonf/api/option"
+ opt "codeberg.org/snonux/gonf/api/options"
"codeberg.org/snonux/gonf/internal/resource"
)
diff --git a/internal/resource/dir/dir_test.go b/internal/resource/dir/dir_test.go
index eb22268..c7ec92e 100644
--- a/internal/resource/dir/dir_test.go
+++ b/internal/resource/dir/dir_test.go
@@ -6,7 +6,7 @@ import (
"testing"
"codeberg.org/snonux/gonf/internal/resource"
- . "codeberg.org/snonux/gonf/api/option"
+ . "codeberg.org/snonux/gonf/api/options"
)
func TestPresentDirectoryCreate(t *testing.T) {
diff --git a/internal/resource/dir/source.go b/internal/resource/dir/source.go
index b94756d..1539590 100644
--- a/internal/resource/dir/source.go
+++ b/internal/resource/dir/source.go
@@ -9,7 +9,7 @@ import (
"codeberg.org/snonux/gonf/internal/resource/file"
"codeberg.org/snonux/gonf/internal/resource/link"
- opt "codeberg.org/snonux/gonf/api/option"
+ opt "codeberg.org/snonux/gonf/api/options"
)
// copySourceTree mirrors d.source into d.path, dispatching each entry by
diff --git a/internal/resource/file/file.go b/internal/resource/file/file.go
index 9879e27..9d8a0d9 100644
--- a/internal/resource/file/file.go
+++ b/internal/resource/file/file.go
@@ -10,7 +10,7 @@ import (
"strings"
"text/template"
- opt "codeberg.org/snonux/gonf/api/option"
+ opt "codeberg.org/snonux/gonf/api/options"
"codeberg.org/snonux/gonf/internal/resource"
)
diff --git a/internal/resource/file/file_test.go b/internal/resource/file/file_test.go
index 7f9fedd..b158657 100644
--- a/internal/resource/file/file_test.go
+++ b/internal/resource/file/file_test.go
@@ -6,7 +6,7 @@ import (
"strings"
"testing"
- . "codeberg.org/snonux/gonf/api/option"
+ . "codeberg.org/snonux/gonf/api/options"
"codeberg.org/snonux/gonf/internal/resource"
)
diff --git a/internal/resource/link/link.go b/internal/resource/link/link.go
index 2bd8c66..a5c5122 100644
--- a/internal/resource/link/link.go
+++ b/internal/resource/link/link.go
@@ -5,7 +5,7 @@ import (
"log"
"os"
- opt "codeberg.org/snonux/gonf/api/option"
+ opt "codeberg.org/snonux/gonf/api/options"
"codeberg.org/snonux/gonf/internal/resource"
)
diff --git a/internal/resource/link/link_test.go b/internal/resource/link/link_test.go
index 3012435..862d5f7 100644
--- a/internal/resource/link/link_test.go
+++ b/internal/resource/link/link_test.go
@@ -6,7 +6,7 @@ import (
"testing"
"codeberg.org/snonux/gonf/internal/resource"
- . "codeberg.org/snonux/gonf/api/option"
+ . "codeberg.org/snonux/gonf/api/options"
)
func TestPresentSymlinkCreateAndIdempotent(t *testing.T) {