Skip to content

Commit

Permalink
Add existence functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tsavola committed Jan 3, 2022
1 parent 780aa81 commit 0516094
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func Fields(s string) []string {
return strings.Fields(s)
}

// Exists path?
func Exists(path string) bool {
_, err := os.Stat(path)
return err == nil || !os.IsNotExist(err)
}

// Glob terminates program on error. Results of multiple pattern will be
// concatenated.
func Glob(patterns ...string) []string {
Expand Down Expand Up @@ -448,6 +454,13 @@ func Outdated(target string, sources func() []string) func() bool {
}
}

// Missing condition.
func Missing(path string) func() bool {
return func() bool {
return !Exists(path)
}
}

// Thunk returns a function which returns the string in a slice.
func Thunk(strings ...string) func() []string {
return func() []string {
Expand Down

0 comments on commit 0516094

Please sign in to comment.