From 756ae621bd97a8b776fefb15e5e7e2292f98ee45 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Thu, 9 Jul 2026 00:14:33 +0300 Subject: dependencies --- examples/examples.go | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'examples/examples.go') diff --git a/examples/examples.go b/examples/examples.go index 7bbfa46..dee9984 100644 --- a/examples/examples.go +++ b/examples/examples.go @@ -67,10 +67,10 @@ func Run() error { _ = os.Link("/tmp/gonf_hello.txt", "/tmp/gonf_stale_hardlink") Link("/tmp/gonf_stale_hardlink", IsAbsent) - // 13. Package management - Package("tig") // Ensure installed (Present) - Package("vim", IsLatest) // Ensure installed and latest version - NoPackage("nano") // Ensure absent + // // 13. Package management + // Package("tig") // Ensure installed (Present) + // Package("vim", IsLatest) // Ensure installed and latest version + // NoPackage("nano") // Ensure absent // 14. Multi-resource declarations // Create multiple files with the same options @@ -86,17 +86,17 @@ func Run() error { ), WithMode(0o755)) // Install multiple packages and ensure they are latest - Package(Elems( - "htop", - "curl", - "wget", - ), IsLatest) - - // Remove multiple packages - NoPackage(Elems( - "old-pkg1", - "old-pkg2", - )) + // Package(Elems( + // "htop", + // "curl", + // "wget", + // ), IsLatest) + + // // Remove multiple packages + // NoPackage(Elems( + // "old-pkg1", + // "old-pkg2", + // )) // Remove multiple files NoFile(Elems( @@ -104,5 +104,22 @@ func Run() error { "/tmp/stale2.txt", )) + // 15. Ordering with DependsOn. bar.txt is only applied after foo.txt. + fooRes := File("/tmp/gonf_foo.txt", WithContent("foo")) + File("/tmp/gonf_bar.txt", WithContent("bar"), DependsOn(fooRes)) + + // DependsOn also accepts multi-resources; the dependent then waits for + // every individual member of the multi. + multiRes := File(Elems( + "/tmp/gonf_dep1.txt", + "/tmp/gonf_dep2.txt", + ), WithContent("dep")) + File("/tmp/gonf_after_multi.txt", WithContent("after"), DependsOn(multiRes)) + + // DependsOn works across resource types and accepts several resources at + // once: this directory is created only after both the file and the multi + // above have been applied. + Dir("/tmp/gonf_after_dir", DependsOn(fooRes, multiRes)) + return Apply() } -- cgit v1.2.3