commit
2b39299214
@ -1,10 +1,12 @@
|
|||||||
settings:
|
settings:
|
||||||
debug: true
|
recovery:
|
||||||
|
events: true
|
||||||
|
tools: true
|
||||||
legacy:
|
legacy:
|
||||||
force: false
|
force: false
|
||||||
interval: 0s
|
interval: 0s
|
||||||
server:
|
server:
|
||||||
status: true
|
status: false
|
||||||
open: true
|
open: true
|
||||||
port: 3000
|
port: 3000
|
||||||
host: localhost
|
host: localhost
|
||||||
@ -13,7 +15,7 @@ schema:
|
|||||||
path: .
|
path: .
|
||||||
commands:
|
commands:
|
||||||
generate:
|
generate:
|
||||||
status: true
|
status: false
|
||||||
install:
|
install:
|
||||||
status: true
|
status: true
|
||||||
vet:
|
vet:
|
||||||
|
@ -54,8 +54,8 @@ func TestLogWriter_Write(t *testing.T) {
|
|||||||
log.SetOutput(&buf)
|
log.SetOutput(&buf)
|
||||||
w := LogWriter{}
|
w := LogWriter{}
|
||||||
input := ""
|
input := ""
|
||||||
int, err := w.Write([]byte(input))
|
val, err := w.Write([]byte(input))
|
||||||
if err != nil || int > 0 {
|
if err != nil || val > 0 {
|
||||||
t.Error("Unexpected error", err, "string lenght should be 0 instead", int)
|
t.Error("Unexpected error", err, "string length should be 0 instead", val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,10 @@ func (p *Project) Reload(path string, stop <-chan bool) {
|
|||||||
}
|
}
|
||||||
// Go supported tools
|
// Go supported tools
|
||||||
if len(path) > 0 {
|
if len(path) > 0 {
|
||||||
fi, err := os.Stat(path)
|
fi, err := os.Stat(filepath.Dir(path))
|
||||||
|
if filepath.Ext(path) == "" {
|
||||||
|
fi, err = os.Stat(path)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.Err(err)
|
p.Err(err)
|
||||||
}
|
}
|
||||||
@ -224,7 +227,6 @@ func (p *Project) Reload(path string, stop <-chan bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if install.Err == nil && build.Err == nil && p.Tools.Run.Status {
|
if install.Err == nil && build.Err == nil && p.Tools.Run.Status {
|
||||||
var start time.Time
|
|
||||||
result := make(chan Response)
|
result := make(chan Response)
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@ -247,7 +249,6 @@ func (p *Project) Reload(path string, stop <-chan bool) {
|
|||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
log.Println(p.pname(p.Name, 1), ":", "Running..")
|
log.Println(p.pname(p.Name, 1), ":", "Running..")
|
||||||
start = time.Now()
|
|
||||||
err := p.run(p.Path, result, stop)
|
err := p.run(p.Path, result, stop)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Regular(err))
|
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Regular(err))
|
||||||
@ -284,7 +285,7 @@ L:
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case event := <-p.watcher.Events():
|
case event := <-p.watcher.Events():
|
||||||
if p.parent.Settings.Debug {
|
if p.parent.Settings.Recovery.Events {
|
||||||
log.Println("Event:", event, "File:", event.Name, "LastFile:", p.lastFile, "Time:", time.Now(), "LastTime:", p.lastTime)
|
log.Println("Event:", event, "File:", event.Name, "LastFile:", p.lastFile, "Time:", time.Now(), "LastTime:", p.lastTime)
|
||||||
}
|
}
|
||||||
if time.Now().Truncate(time.Second).After(p.lastTime) || event.Name != p.lastFile {
|
if time.Now().Truncate(time.Second).After(p.lastTime) || event.Name != p.lastFile {
|
||||||
@ -403,6 +404,7 @@ func (p *Project) tools(stop <-chan bool, path string, fi os.FileInfo) {
|
|||||||
go func() {
|
go func() {
|
||||||
for i := 0; i < v.NumField()-1; i++ {
|
for i := 0; i < v.NumField()-1; i++ {
|
||||||
tool := v.Field(i).Interface().(Tool)
|
tool := v.Field(i).Interface().(Tool)
|
||||||
|
tool.parent = p
|
||||||
if tool.Status && tool.isTool {
|
if tool.Status && tool.isTool {
|
||||||
if fi.IsDir() {
|
if fi.IsDir() {
|
||||||
if tool.dir {
|
if tool.dir {
|
||||||
@ -423,6 +425,9 @@ func (p *Project) tools(stop <-chan bool, path string, fi os.FileInfo) {
|
|||||||
return
|
return
|
||||||
case r := <-result:
|
case r := <-result:
|
||||||
if r.Err != nil {
|
if r.Err != nil {
|
||||||
|
if fi.IsDir(){
|
||||||
|
path, _ = filepath.Abs(fi.Name())
|
||||||
|
}
|
||||||
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), Red.Regular("there are some errors in"), ":", Magenta.Bold(path))
|
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", Red.Bold(r.Name), Red.Regular("there are some errors in"), ":", Magenta.Bold(path))
|
||||||
buff := BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: r.Name, Stream: r.Err.Error()}
|
buff := BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: r.Name, Stream: r.Err.Error()}
|
||||||
p.stamp("error", buff, msg, r.Err.Error())
|
p.stamp("error", buff, msg, r.Err.Error())
|
||||||
@ -472,9 +477,9 @@ func (p *Project) walk(path string, info os.FileInfo, err error) error {
|
|||||||
if p.Validate(path, true) {
|
if p.Validate(path, true) {
|
||||||
result := p.watcher.Walk(path, p.init)
|
result := p.watcher.Walk(path, p.init)
|
||||||
if result != "" {
|
if result != "" {
|
||||||
p.tools(p.stop, path, info)
|
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
// tools dir
|
// tools dir
|
||||||
|
p.tools(p.stop, path, info)
|
||||||
p.folders++
|
p.folders++
|
||||||
} else {
|
} else {
|
||||||
// tools files
|
// tools files
|
||||||
|
@ -29,10 +29,14 @@ const (
|
|||||||
// Settings defines a group of general settings and options
|
// Settings defines a group of general settings and options
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
Files `yaml:"files,omitempty" json:"files,omitempty"`
|
Files `yaml:"files,omitempty" json:"files,omitempty"`
|
||||||
Recovery bool `yaml:"recovery,omitempty" json:"recovery,omitempty"`
|
|
||||||
Debug bool `yaml:"debug,omitempty" json:"debug,omitempty"`
|
|
||||||
FileLimit int32 `yaml:"flimit,omitempty" json:"flimit,omitempty"`
|
FileLimit int32 `yaml:"flimit,omitempty" json:"flimit,omitempty"`
|
||||||
Legacy Legacy `yaml:"legacy" json:"legacy"`
|
Legacy Legacy `yaml:"legacy" json:"legacy"`
|
||||||
|
Recovery Recovery `yaml:"recovery,omitempty" json:"recovery,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Recovery struct {
|
||||||
|
Events bool
|
||||||
|
Tools bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy is used to force polling and set a custom interval
|
// Legacy is used to force polling and set a custom interval
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -21,6 +22,7 @@ type Tool struct {
|
|||||||
method []string
|
method []string
|
||||||
cmd []string
|
cmd []string
|
||||||
name string
|
name string
|
||||||
|
parent *Project
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tools go
|
// Tools go
|
||||||
@ -117,6 +119,9 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
|
|||||||
path = filepath.Dir(path)
|
path = filepath.Dir(path)
|
||||||
}
|
}
|
||||||
if s := ext(path); s == "" || s == "go" {
|
if s := ext(path); s == "" || s == "go" {
|
||||||
|
if t.parent.parent.Settings.Recovery.Tools {
|
||||||
|
log.Println("Tool:", t.name, path, args)
|
||||||
|
}
|
||||||
var out, stderr bytes.Buffer
|
var out, stderr bytes.Buffer
|
||||||
done := make(chan error)
|
done := make(chan error)
|
||||||
args = append(t.cmd, args...)
|
args = append(t.cmd, args...)
|
||||||
|
Loading…
Reference in New Issue
Block a user