-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwatchmod_test.go
More file actions
50 lines (45 loc) · 896 Bytes
/
watchmod_test.go
File metadata and controls
50 lines (45 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package watchmod
import (
"fmt"
"io/ioutil"
"log"
"os"
"time"
)
// ExampleRun
func ExampleRun() {
ParseFlags()
FC.Daemon = false
Run()
// Output:
// Config path: watchmod.json5
// Flag `daemon` set to false. Running commands in config and exiting.
}
// Create a file, write to it, and delete it.
func touch() {
fileName := "temp.txt"
_, err := os.Stat(fileName)
if os.IsNotExist(err) {
file, err := os.Create("temp.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
} else {
currentTime := time.Now().Local()
err = os.Chtimes(fileName, currentTime, currentTime)
if err != nil {
fmt.Println(err)
}
}
b := []byte("hello watchmod!")
err = ioutil.WriteFile(fileName, b, 0644)
if err != nil {
fmt.Println("Could not write to: " + fileName)
return
}
e := os.Remove(fileName)
if e != nil {
fmt.Println("Could not remove: " + fileName)
}
}