Skip to content

Commit 0507e50

Browse files
committed
Init commit
0 parents  commit 0507e50

File tree

336 files changed

+233253
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

336 files changed

+233253
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, build with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool, specifically when used with LiteIDE
12+
*.out
13+
14+
# Releases directory
15+
/release

Gopkg.lock

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
#
22+
# [prune]
23+
# non-go = false
24+
# go-tests = true
25+
# unused-packages = true
26+
27+
28+
[prune]
29+
go-tests = true
30+
unused-packages = true

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
release:
2+
mkdir -p release/macos
3+
mkdir release/linux
4+
mkdir release/windows
5+
GOOS=darwin go build -o release/macos/multiwatch
6+
GOOS=linux go build -o release/linux/multiwatch
7+
GOOS=windows go build -o release/windows/multiwatch.exe

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# multiwatch
2+
Simple task runner on directory changes

main.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package main
2+
3+
import (
4+
"github.com/BurntSushi/toml"
5+
"github.com/Enapiuz/multiwatch/printer"
6+
"github.com/Enapiuz/multiwatch/watcher"
7+
"log"
8+
)
9+
10+
type DirectoryConfig struct {
11+
Name string
12+
Paths []string
13+
Commands []string
14+
}
15+
16+
type Config struct {
17+
Delay int32
18+
Watch []DirectoryConfig
19+
}
20+
21+
func main() {
22+
var config Config
23+
var watchers = make([]*watcher.Watcher, 0)
24+
needReprint := make(chan bool)
25+
_, err := toml.DecodeFile("multiwatch.toml", &config)
26+
if err != nil {
27+
log.Fatal(err)
28+
}
29+
for _, watchConfig := range config.Watch {
30+
log.Printf("%v", watchConfig)
31+
dirWatcher := watcher.NewWatcher(watchConfig.Name, watchConfig.Paths, watchConfig.Commands)
32+
dirWatcher.Run(needReprint)
33+
watchers = append(watchers, dirWatcher)
34+
}
35+
36+
log.Printf("%d", len(watchers))
37+
38+
var statusPrinter = printer.NewPrinter()
39+
statusPrinter.RegisterWatchers(watchers)
40+
statusPrinter.Start(needReprint)
41+
needReprint <- true
42+
43+
done := make(chan bool)
44+
<-done
45+
}

multiwatch.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
delay=500
2+
3+
[[watch]]
4+
name = "linter"
5+
paths = ["vendor/github.com"]
6+
commands = ["sleep 1", "sleep 1", "ls /sfsdfsdf"]
7+
8+
[[watch]]
9+
name = "tests"
10+
paths = ["vendor/golang.org"]
11+
commands = ["sleep 5"]

printer/printer.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package printer
2+
3+
import (
4+
"fmt"
5+
"github.com/Enapiuz/multiwatch/watcher"
6+
"os"
7+
"os/exec"
8+
"runtime"
9+
)
10+
11+
type Printer struct {
12+
watchers []*watcher.Watcher
13+
clear map[string]func()
14+
}
15+
16+
func NewPrinter() *Printer {
17+
clear := make(map[string]func())
18+
clear["darwin"] = func() {
19+
cmd := exec.Command("clear")
20+
cmd.Stdout = os.Stdout
21+
cmd.Run()
22+
}
23+
clear["linux"] = func() {
24+
cmd := exec.Command("clear")
25+
cmd.Stdout = os.Stdout
26+
cmd.Run()
27+
}
28+
clear["windows"] = func() {
29+
cmd := exec.Command("cmd", "/c", "cls")
30+
cmd.Stdout = os.Stdout
31+
cmd.Run()
32+
}
33+
return &Printer{clear: clear}
34+
}
35+
36+
func (p *Printer) RegisterWatchers(watchers []*watcher.Watcher) {
37+
p.watchers = watchers
38+
}
39+
40+
func (p *Printer) Start(needReprint chan bool) {
41+
go func() {
42+
for {
43+
select {
44+
case _ = <-needReprint:
45+
p.printWatchers()
46+
}
47+
}
48+
}()
49+
}
50+
51+
func (p *Printer) printWatchers() {
52+
p.callClear()
53+
for _, localWatcher := range p.watchers {
54+
fmt.Println(localWatcher.GetStatus())
55+
}
56+
}
57+
58+
func (p *Printer) callClear() {
59+
value, ok := p.clear[runtime.GOOS] //runtime.GOOS -> linux, windows, darwin etc.
60+
if ok { //if we defined a clear func for that platform:
61+
value() //we execute it
62+
} else { //unsupported platform
63+
panic("Your platform is unsupported! I can't clear terminal screen :(")
64+
}
65+
}

vendor/github.com/BurntSushi/toml/.gitignore

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)