-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinotify-proxy.go
90 lines (70 loc) · 2.42 KB
/
inotify-proxy.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"flag"
"os"
"strings"
"github.com/cmuench/inotify-proxy/internal/config"
"github.com/cmuench/inotify-proxy/internal/util"
"github.com/cmuench/inotify-proxy/internal/watcher"
"github.com/gookit/color"
)
// Version defines the version of the application. This variable will be overridden by build system
var Version = "dev"
func main() {
color.Style{color.FgWhite, color.FgDarkGray}.Printf("Version: %s\n", Version)
sleepPtr := flag.Int("sleep", 2, "Cycle time in seconds. Defines time to sleep after each filesystem walk. Default 2s")
profilePtr := flag.String("profile", "default", "Defines a special profile with extensions to look for. This speeds up the process. Available profiles are 'magento2-theme'")
noConfig := flag.Bool("no-config", false, "Do not load config.")
flag.Parse()
includedDirectories := flag.Args()
c := config.Config{}
if !*noConfig {
if util.FileExists("inotify-proxy.yaml") {
r, err := os.Open("inotify-proxy.yaml")
if err != nil {
color.Errorf("cannot read file: %v\n", err)
os.Exit(1)
}
defer r.Close()
c, err = config.Read(r)
if err != nil {
color.Errorf("cannot read config: %v\n", err)
}
if c.OldGlobalProfile != nil {
color.Errorf("You are using the old configuration format. Please use the new configuration version.\n")
color.Print("\nPlease refer: https://github.com/cmuench/inotify-proxy/blob/master/README.md#config\n")
os.Exit(1)
}
}
}
if len(includedDirectories) > 0 {
for _, includedDirectory := range includedDirectories {
c.Entries = append(c.Entries, config.WatchEntry{
Directory: includedDirectory,
Extensions: nil,
Profile: profilePtr,
})
}
}
// If no argument is defined, the current directory is used
if len(c.Entries) == 0 {
c.AddEntry(config.WatchEntry{
Directory: ".",
Extensions: nil,
Profile: profilePtr,
})
}
color.Style{color.FgMagenta, color.OpBold}.Println("Watching ...")
color.Style{color.FgWhite}.Println(strings.Repeat("-", 80))
for _, e := range c.Entries {
color.Style{color.FgCyan, color.OpBold}.Printf("Directory: %s\n", e.Directory)
if e.Profile != nil {
color.Style{color.FgCyan, color.OpBold}.Printf("Profile: %s\n", *e.Profile)
}
if len(e.Extensions) > 0 {
color.Style{color.FgCyan, color.OpBold}.Printf("Extensions: %s\n", e.Extensions)
}
color.Style{color.FgWhite}.Println(strings.Repeat("-", 80))
}
watcher.Watch(c, *sleepPtr)
}