-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Releases directory | ||
/release |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Gopkg.toml example | ||
# | ||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html | ||
# for detailed Gopkg.toml documentation. | ||
# | ||
# required = ["github.com/user/thing/cmd/thing"] | ||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project" | ||
# version = "1.0.0" | ||
# | ||
# [[constraint]] | ||
# name = "github.com/user/project2" | ||
# branch = "dev" | ||
# source = "github.com/myfork/project2" | ||
# | ||
# [[override]] | ||
# name = "github.com/x/y" | ||
# version = "2.4.0" | ||
# | ||
# [prune] | ||
# non-go = false | ||
# go-tests = true | ||
# unused-packages = true | ||
|
||
|
||
[prune] | ||
go-tests = true | ||
unused-packages = true |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
release: | ||
mkdir -p release/macos | ||
mkdir release/linux | ||
mkdir release/windows | ||
GOOS=darwin go build -o release/macos/multiwatch | ||
GOOS=linux go build -o release/linux/multiwatch | ||
GOOS=windows go build -o release/windows/multiwatch.exe |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# multiwatch | ||
Simple task runner on directory changes |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/BurntSushi/toml" | ||
"github.com/Enapiuz/multiwatch/printer" | ||
"github.com/Enapiuz/multiwatch/watcher" | ||
"log" | ||
) | ||
|
||
type DirectoryConfig struct { | ||
Name string | ||
Paths []string | ||
Commands []string | ||
} | ||
|
||
type Config struct { | ||
Delay int32 | ||
Watch []DirectoryConfig | ||
} | ||
|
||
func main() { | ||
var config Config | ||
var watchers = make([]*watcher.Watcher, 0) | ||
needReprint := make(chan bool) | ||
_, err := toml.DecodeFile("multiwatch.toml", &config) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
for _, watchConfig := range config.Watch { | ||
log.Printf("%v", watchConfig) | ||
dirWatcher := watcher.NewWatcher(watchConfig.Name, watchConfig.Paths, watchConfig.Commands) | ||
dirWatcher.Run(needReprint) | ||
watchers = append(watchers, dirWatcher) | ||
} | ||
|
||
log.Printf("%d", len(watchers)) | ||
|
||
var statusPrinter = printer.NewPrinter() | ||
statusPrinter.RegisterWatchers(watchers) | ||
statusPrinter.Start(needReprint) | ||
needReprint <- true | ||
|
||
done := make(chan bool) | ||
<-done | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
delay=500 | ||
|
||
[[watch]] | ||
name = "linter" | ||
paths = ["vendor/github.com"] | ||
commands = ["sleep 1", "sleep 1", "ls /sfsdfsdf"] | ||
|
||
[[watch]] | ||
name = "tests" | ||
paths = ["vendor/golang.org"] | ||
commands = ["sleep 5"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package printer | ||
|
||
import ( | ||
"fmt" | ||
"github.com/Enapiuz/multiwatch/watcher" | ||
"os" | ||
"os/exec" | ||
"runtime" | ||
) | ||
|
||
type Printer struct { | ||
watchers []*watcher.Watcher | ||
clear map[string]func() | ||
} | ||
|
||
func NewPrinter() *Printer { | ||
clear := make(map[string]func()) | ||
clear["darwin"] = func() { | ||
cmd := exec.Command("clear") | ||
cmd.Stdout = os.Stdout | ||
cmd.Run() | ||
} | ||
clear["linux"] = func() { | ||
cmd := exec.Command("clear") | ||
cmd.Stdout = os.Stdout | ||
cmd.Run() | ||
} | ||
clear["windows"] = func() { | ||
cmd := exec.Command("cmd", "/c", "cls") | ||
cmd.Stdout = os.Stdout | ||
cmd.Run() | ||
} | ||
return &Printer{clear: clear} | ||
} | ||
|
||
func (p *Printer) RegisterWatchers(watchers []*watcher.Watcher) { | ||
p.watchers = watchers | ||
} | ||
|
||
func (p *Printer) Start(needReprint chan bool) { | ||
go func() { | ||
for { | ||
select { | ||
case _ = <-needReprint: | ||
p.printWatchers() | ||
} | ||
} | ||
}() | ||
} | ||
|
||
func (p *Printer) printWatchers() { | ||
p.callClear() | ||
for _, localWatcher := range p.watchers { | ||
fmt.Println(localWatcher.GetStatus()) | ||
} | ||
} | ||
|
||
func (p *Printer) callClear() { | ||
value, ok := p.clear[runtime.GOOS] //runtime.GOOS -> linux, windows, darwin etc. | ||
if ok { //if we defined a clear func for that platform: | ||
value() //we execute it | ||
} else { //unsupported platform | ||
panic("Your platform is unsupported! I can't clear terminal screen :(") | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.