From 6a2796f31444b21488ab9d383292841613a1d9c7 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 4 Jul 2026 23:00:04 +0300 Subject: minor refactor --- examples/examples.go | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'examples/examples.go') 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 } -- cgit v1.2.3