summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-04 23:00:04 +0300
committerPaul Buetow <paul@buetow.org>2026-07-04 23:00:04 +0300
commit6a2796f31444b21488ab9d383292841613a1d9c7 (patch)
tree54005b0e379d2d5b16012cec3563eccd321c9968 /examples
parent2c4c430e6f95f9c2569a610fb7b0e8f0b6e71f28 (diff)
minor refactor
Diffstat (limited to 'examples')
-rw-r--r--examples/examples.go37
1 files changed, 20 insertions, 17 deletions
diff --git a/examples/examples.go b/examples/examples.go
index 180b446..8fe0f0d 100644
--- a/examples/examples.go
+++ b/examples/examples.go
@@ -1,31 +1,34 @@
package examples
import (
- "fmt"
-
"codeberg.org/snonux/gonf/internal/file"
)
func Run() error {
- if err := file.Have("/tmp/gonf_example.conf", file.WithSource("source://assets/testfiles/test.tmpl")); err != nil {
- return fmt.Errorf("failed to create example conf: %w", err)
- }
+ // 1. Regular file with content
+ file.Have("/tmp/gonf_hello.txt", file.WithContent("Hello World!"))
+
+ // 2. Regular file from a source template
+ file.Have("/tmp/gonf_example.conf", file.WithSource("assets/testfiles/test.tmpl"))
+
+ // 3. Regular file with specific mode and owner
+ file.Have(
+ "/tmp/gonf_secret.txt",
+ file.WithContent("top secret"),
+ file.WithMode(0o600),
+ )
- if err := file.Have("/tmp/foo.txt", file.WithContent("hi")); err != nil {
- return fmt.Errorf("failed to create foo.txt: %w", err)
- }
+ // 4. A directory
+ file.Have("/tmp/gonf_dir", file.IsDirectory(), file.WithMode(0o755))
- if err := file.Have("/tmp/gonf_example_dir", file.IsDirectory(), file.WithMode(0o755)); err != nil {
- return fmt.Errorf("failed to create example dir: %w", err)
- }
+ // 5. A symlink
+ file.Have("/tmp/gonf_link", file.IsSymlink("/tmp/gonf_hello.txt"))
- if err := file.Have("/tmp/gonf_example_link", file.IsSymlink("/tmp/foo.txt")); err != nil {
- return fmt.Errorf("failed to create example symlink: %w", err)
- }
+ // 6. A hardlink
+ file.Have("/tmp/gonf_hardlink", file.IsHardlink("/tmp/gonf_hello.txt"))
- if err := file.Have("/tmp/gonf_example_hardlink", file.Hardlink("/tmp/foo.txt")); err != nil {
- return fmt.Errorf("failed to create example hardlink: %w", err)
- }
+ // 7. Ensuring something is absent
+ file.Have("/tmp/gonf_old.txt", file.IsAbsent())
return nil
}