-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
63 lines (49 loc) · 1.15 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
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 {
fatalf("err: %s\n", err.Error())
}
if args.Path != "" && !validPath(args.Path) {
fatalf("err: invalid path %q\n", args.Path)
}
if args.Path == "" {
args.Path = wd
}
c := &CommandsFile{}
data, err := os.ReadFile(args.File)
if err != nil {
fatalf("err: %s\n", err.Error())
}
err = c.Parse(data)
if err != nil {
fatalf("err: %s\n", err.Error())
}
watcher, err := fsnotify.NewWatcher()
if err != nil {
fatalf("err: %s\n", err.Error())
}
defer watcher.Close()
if args.Recursive {
addPathRecursively(args.Path, watcher)
} else {
watcher.Add(args.Path)
}
watchEvents(watcher, *c)
}