-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
64 lines (50 loc) · 1.2 KB
/
main.go
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"fmt"
"os"
"github.com/alexflint/go-arg"
"github.com/fsnotify/fsnotify"
)
func init() {
fmt.Println(`
_ __ ______ / /_ _____ / /_ ___ _____
| | /| / // __ // __// ___// __ \ / _ \ / ___/
| |/ |/ // /_/ // /_ / /__ / / / // __// /
|__/|__/ \____/ \__/ \___//_/ /_/ \___//_/
`)
}
func main() {
var args args
arg.MustParse(&args)
wd, err := os.Getwd()
if err != nil {
fmt.Fprintf(os.Stderr, "err: %s\n", err.Error())
os.Exit(1)
}
if args.Path != "" && !validPath(args.Path) {
fmt.Fprintf(os.Stderr, "err: %s\n", "invalid path: "+args.Path)
os.Exit(1)
}
if args.Path == "" {
args.Path = wd
}
c := &CommandsFile{}
data, err := os.ReadFile(args.File)
if err != nil {
fmt.Fprintf(os.Stderr, "err: %s\n", err.Error())
os.Exit(1)
}
c.Parse(data)
watcher, err := fsnotify.NewWatcher()
if err != nil {
fmt.Fprintf(os.Stderr, "err: %s\n", err.Error())
os.Exit(1)
}
defer watcher.Close()
if args.Recursive {
addPathRecursively(args.Path, watcher)
} else {
watcher.Add(args.Path)
}
watchEvents(watcher, *c)
}