1
0
mirror of https://github.com/go-task/task.git synced 2025-01-20 04:59:37 +02:00

Change patterns to slice to support multiple

This commit is contained in:
Andrey Nering 2017-02-27 17:03:25 -03:00
parent 0e1aaabf11
commit b8b52b94f9
2 changed files with 41 additions and 7 deletions

38
file.go
View File

@ -12,7 +12,41 @@ var dirsToSkip = []string{
"node_modules",
}
func minTime(pattern string) (minTime time.Time, err error) {
func minTime(a, b time.Time) time.Time {
if !a.IsZero() && a.Before(b) {
return a
}
return b
}
func maxTime(a, b time.Time) time.Time {
if a.After(b) {
return a
}
return b
}
func getPatternsMinTime(patterns []string) (m time.Time, err error) {
for _, p := range patterns {
mp, err := getPatternMinTime(p)
if err != nil {
return time.Time{}, err
}
m = minTime(m, mp)
}
return
}
func getPatternsMaxTime(patterns []string) (m time.Time, err error) {
for _, p := range patterns {
mp, err := getPatternMaxTime(p)
if err != nil {
return time.Time{}, err
}
m = maxTime(m, mp)
}
return
}
func getPatternMinTime(pattern string) (minTime time.Time, err error) {
files, err := zglob.Glob(pattern)
if err != nil {
return time.Time{}, err
@ -32,7 +66,7 @@ func minTime(pattern string) (minTime time.Time, err error) {
return
}
func maxTime(pattern string) (maxTime time.Time, err error) {
func getPatternMaxTime(pattern string) (maxTime time.Time, err error) {
files, err := zglob.Glob(pattern)
if err != nil {
return time.Time{}, err

10
task.go
View File

@ -30,8 +30,8 @@ func init() {
type Task struct {
Cmds []string
Deps []string
Sources string
Generates string
Sources []string
Generates []string
}
type TaskNotFoundError struct {
@ -104,16 +104,16 @@ func RunTask(name string) error {
}
func isTaskUpToDate(t *Task) bool {
if t.Sources == "" || t.Generates == "" {
if len(t.Sources) == 0 || len(t.Generates) == 0 {
return false
}
sourcesMaxTime, err := maxTime(t.Sources)
sourcesMaxTime, err := getPatternsMaxTime(t.Sources)
if err != nil || sourcesMaxTime.IsZero() {
return false
}
generatesMinTime, err := minTime(t.Generates)
generatesMinTime, err := getPatternsMinTime(t.Generates)
if err != nil || generatesMinTime.IsZero() {
return false
}