diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-09 00:14:33 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-09 00:14:33 +0300 |
| commit | 756ae621bd97a8b776fefb15e5e7e2292f98ee45 (patch) | |
| tree | b454f958e6aef70bf7ca40dcbc106323cee2a42f /examples | |
| parent | 3f8b79f2b1384e3abc2b1bb2fe913688c7ec251c (diff) | |
dependencies
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/examples.go | 47 |
1 files changed, 32 insertions, 15 deletions
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() } |
