Browse Source

Initial import (not yet complete)

master
Chris Smith 7 years ago
commit
8c6e7f409e
1 changed files with 58 additions and 0 deletions
  1. 58
    0
      hupper.go

+ 58
- 0
hupper.go View File

@@ -0,0 +1,58 @@
1
+package main
2
+
3
+import (
4
+	"flag"
5
+	"fmt"
6
+	"golang.org/x/exp/inotify"
7
+	"strings"
8
+)
9
+
10
+type arrayFlags []string
11
+
12
+func (i *arrayFlags) String() string {
13
+	return strings.Join(*i, ", ")
14
+}
15
+
16
+func (i *arrayFlags) Set(value string) error {
17
+	*i = append(*i, value)
18
+	return nil
19
+}
20
+
21
+func main() {
22
+	var paths arrayFlags
23
+	var container string
24
+
25
+	flag.Var(&paths, "path", "Path to monitor for changes (may be specified multiple times)")
26
+	flag.StringVar(&container, "container", "nginx", "Name of the container in which nginx is running")
27
+	flag.Parse()
28
+
29
+	fmt.Printf("Hello, world.\nPaths: %v\nContainer: %v\n", paths, container)
30
+
31
+	if len(paths) == 0 {
32
+		panic("No paths specified")
33
+	}
34
+
35
+	watch_for_changes(paths)
36
+}
37
+
38
+func watch_for_changes(paths []string) {
39
+	watcher, err := inotify.NewWatcher()
40
+	if err != nil {
41
+		panic(err)
42
+	}
43
+
44
+	defer watcher.Close()
45
+
46
+	for _, path := range paths {
47
+		watcher.Watch(path)
48
+	}
49
+
50
+	for {
51
+		select {
52
+		case event := <-watcher.Event:
53
+			panic(event)
54
+		case err := <-watcher.Error:
55
+			panic(err)
56
+		}
57
+	}
58
+}

Loading…
Cancel
Save