| 1 |
package godo |
| 2 |
|
| 3 |
import ( |
| 4 |
"time" |
| 5 |
|
| 6 |
"gopkg.in/godo.v2/util" |
| 7 |
"github.com/mgutz/str" |
| 8 |
) |
| 9 |
|
| 10 |
|
| 11 |
type Dependency interface { |
| 12 |
markAsDependency() |
| 13 |
} |
| 14 |
|
| 15 |
|
| 16 |
type Series []interface{} |
| 17 |
|
| 18 |
func (s Series) names() []string { |
| 19 |
names := []string{} |
| 20 |
for _, step := range s { |
| 21 |
switch t := step.(type) { |
| 22 |
case string: |
| 23 |
if str.SliceIndexOf(names, t) < 0 { |
| 24 |
names = append(names, t) |
| 25 |
} |
| 26 |
case Series: |
| 27 |
names = append(names, t.names()...) |
| 28 |
case Parallel: |
| 29 |
names = append(names, t.names()...) |
| 30 |
} |
| 31 |
|
| 32 |
} |
| 33 |
return names |
| 34 |
} |
| 35 |
|
| 36 |
func (s Series) markAsDependency() {} |
| 37 |
|
| 38 |
|
| 39 |
type Parallel []interface{} |
| 40 |
|
| 41 |
func (p Parallel) names() []string { |
| 42 |
names := []string{} |
| 43 |
for _, step := range p { |
| 44 |
switch t := step.(type) { |
| 45 |
case string: |
| 46 |
if str.SliceIndexOf(names, t) < 0 { |
| 47 |
names = append(names, t) |
| 48 |
} |
| 49 |
case Series: |
| 50 |
names = append(names, t.names()...) |
| 51 |
case Parallel: |
| 52 |
names = append(names, t.names()...) |
| 53 |
} |
| 54 |
|
| 55 |
} |
| 56 |
return names |
| 57 |
} |
| 58 |
|
| 59 |
func (p Parallel) markAsDependency() {} |
| 60 |
|
| 61 |
|
| 62 |
type S []interface{} |
| 63 |
|
| 64 |
func (s S) markAsDependency() {} |
| 65 |
|
| 66 |
|
| 67 |
type P []interface{} |
| 68 |
|
| 69 |
func (p P) markAsDependency() {} |
| 70 |
|
| 71 |
|
| 72 |
func (task *Task) Debounce(duration time.Duration) *Task { |
| 73 |
if duration > 0 { |
| 74 |
task.debounce = duration |
| 75 |
} |
| 76 |
return task |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
func (task *Task) Deps(names ...interface{}) { |
| 81 |
for _, name := range names { |
| 82 |
switch dep := name.(type) { |
| 83 |
default: |
| 84 |
util.Error(task.Name, "Dependency types must be (string | P | Parallel | S | Series)") |
| 85 |
case string: |
| 86 |
task.dependencies = append(task.dependencies, dep) |
| 87 |
case P: |
| 88 |
task.dependencies = append(task.dependencies, Parallel(dep)) |
| 89 |
case Parallel: |
| 90 |
task.dependencies = append(task.dependencies, dep) |
| 91 |
case S: |
| 92 |
task.dependencies = append(task.dependencies, Series(dep)) |
| 93 |
case Series: |
| 94 |
task.dependencies = append(task.dependencies, dep) |
| 95 |
} |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
func (task *Task) Description(desc string) *Task { |
| 101 |
if desc != "" { |
| 102 |
task.description = desc |
| 103 |
} |
| 104 |
return task |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
func (task *Task) Desc(desc string) *Task { |
| 109 |
return task.Description(desc) |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
func (task *Task) Dest(globs ...string) *Task { |
| 116 |
if len(globs) > 0 { |
| 117 |
task.DestGlobs = globs |
| 118 |
} |
| 119 |
return task |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
func (task *Task) Src(globs ...string) *Task { |
| 125 |
if len(globs) > 0 { |
| 126 |
task.SrcGlobs = globs |
| 127 |
} |
| 128 |
return task |
| 129 |
} |