| 1 |
package godo |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"io/ioutil" |
| 6 |
"os" |
| 7 |
"path/filepath" |
| 8 |
"strconv" |
| 9 |
"time" |
| 10 |
) |
| 11 |
|
| 12 |
|
| 13 |
var testProjectDelay = 150 * time.Millisecond |
| 14 |
var testWatchDelay time.Duration |
| 15 |
|
| 16 |
func init() { |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
SetWatchDelay(150 * time.Millisecond) |
| 25 |
|
| 26 |
testWatchDelay = watchDelay*2 + 50 |
| 27 |
|
| 28 |
|
| 29 |
Debounce = 100 * time.Millisecond |
| 30 |
verbose = false |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
func runTask(tasksFn func(*Project), name string) (*Project, error) { |
| 35 |
proj := NewProject(tasksFn, func(status int) { |
| 36 |
|
| 37 |
panic("exited with code" + strconv.Itoa(status)) |
| 38 |
}, nil) |
| 39 |
return proj, proj.Run(name) |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
func execCLI(tasksFn func(*Project), argv []string, customExitFn func(int)) int { |
| 44 |
var code int |
| 45 |
var exitFn func(code int) |
| 46 |
if customExitFn == nil { |
| 47 |
exitFn = func(status int) { |
| 48 |
code = status |
| 49 |
} |
| 50 |
} else { |
| 51 |
exitFn = func(status int) { |
| 52 |
code = status |
| 53 |
customExitFn(status) |
| 54 |
} |
| 55 |
} |
| 56 |
godoExit(tasksFn, argv, exitFn) |
| 57 |
return code |
| 58 |
} |
| 59 |
|
| 60 |
func touch(path string, delta time.Duration) { |
| 61 |
if _, err := os.Stat(path); err == nil { |
| 62 |
tn := time.Now() |
| 63 |
tn = tn.Add(delta) |
| 64 |
err := os.Chtimes(path, tn, tn) |
| 65 |
if err != nil { |
| 66 |
fmt.Printf("Err touching %s\n", err.Error()) |
| 67 |
} |
| 68 |
|
| 69 |
return |
| 70 |
} |
| 71 |
os.MkdirAll(filepath.Dir(path), 0755) |
| 72 |
ioutil.WriteFile(path, []byte{}, 0644) |
| 73 |
} |
| 74 |
|
| 75 |
func touchTil(filename string, timeout time.Duration, cquit chan bool) { |
| 76 |
filename, _ = filepath.Abs(filename) |
| 77 |
forloop: |
| 78 |
for { |
| 79 |
select { |
| 80 |
case <-cquit: |
| 81 |
break forloop |
| 82 |
case <-time.After(timeout): |
| 83 |
touch(filename, 1*time.Minute) |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
func sliceContains(slice []string, val string) bool { |
| 89 |
for _, it := range slice { |
| 90 |
if it == val { |
| 91 |
return true |
| 92 |
} |
| 93 |
} |
| 94 |
return false |
| 95 |
} |