Skip to content

Commit

Permalink
Init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Enapiuz committed May 10, 2019
0 parents commit 0507e50
Show file tree
Hide file tree
Showing 336 changed files with 233,253 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
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
45 changes: 45 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions Gopkg.toml
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
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Makefile
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# multiwatch
Simple task runner on directory changes
45 changes: 45 additions & 0 deletions main.go
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
}
11 changes: 11 additions & 0 deletions multiwatch.toml
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"]
65 changes: 65 additions & 0 deletions printer/printer.go
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 :(")
}
}
5 changes: 5 additions & 0 deletions vendor/github.com/BurntSushi/toml/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions vendor/github.com/BurntSushi/toml/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/github.com/BurntSushi/toml/COMPATIBLE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/BurntSushi/toml/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/github.com/BurntSushi/toml/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0507e50

Please sign in to comment.