This commit is contained in:
alessio 2017-09-17 10:31:58 +02:00
parent 3b3453da46
commit 9df2440e7a
2 changed files with 25 additions and 21 deletions

View File

@ -145,8 +145,8 @@ func (p *Project) goInstall() (string, error) {
return "", nil return "", nil
} }
// GoTools is used for run go methods such as fmt, test, generate... // GoTool is used for run go methods such as fmt, test, generate...
func (p *Project) goTools(dir string, name string, cmd ...string) (string, error) { func (p *Project) goTool(dir string, name string, cmd ...string) (string, error) {
if s := filepath.Ext(dir); s != "" && s != ".go" { if s := filepath.Ext(dir); s != "" && s != ".go" {
return "", nil return "", nil
} }

View File

@ -124,27 +124,31 @@ func (p *Project) watchByNotify() {
if event.Op&fsnotify.Chmod == fsnotify.Chmod { if event.Op&fsnotify.Chmod == fsnotify.Chmod {
continue continue
} }
if _, err := os.Stat(event.Name); err == nil { var ext string
var ext string if index := strings.Index(filepath.Ext(event.Name), "_"); index == -1 {
if index := strings.Index(filepath.Ext(event.Name), "_"); index == -1 { ext = filepath.Ext(event.Name)
ext = filepath.Ext(event.Name) } else {
} else { ext = filepath.Ext(event.Name)[0:index]
ext = filepath.Ext(event.Name)[0:index] }
i := strings.Index(event.Name, filepath.Ext(event.Name))
file := event.Name[:i] + ext
if event.Name[:i] != "" && inArray(ext, p.Watcher.Exts) {
if p.Cmds.Run {
close(channel)
channel = make(chan bool)
} }
i := strings.Index(event.Name, filepath.Ext(event.Name)) // repeat the initial cycle
file := event.Name[:i] + ext msg = fmt.Sprintln(p.pname(p.Name, 4), ":", style.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), style.Magenta.Bold(file))
if event.Name[:i] != "" && inArray(ext, p.Watcher.Exts) { out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + file}
if p.Cmds.Run { p.stamp("log", out, msg, "")
close(channel)
channel = make(chan bool) // check if is deleted
} if event.Op&fsnotify.Remove == fsnotify.Remove {
// repeat the initial cycle go p.routines(&wr, channel, watcher, "")
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", style.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), style.Magenta.Bold(file)) }else{
out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + file}
p.stamp("log", out, msg, "")
go p.routines(&wr, channel, watcher, file) go p.routines(&wr, channel, watcher, file)
p.LastChangedOn = time.Now().Truncate(time.Second)
} }
p.LastChangedOn = time.Now().Truncate(time.Second)
} }
} }
case err := <-watcher.Errors: case err := <-watcher.Errors:
@ -267,7 +271,7 @@ func (p *Project) tool(path string, tool tool) error {
tool.options = append(tool.options, path) tool.options = append(tool.options, path)
path = p.base path = p.base
} }
if stream, err := p.goTools(path, tool.cmd, tool.options...); err != nil { if stream, err := p.goTool(path, tool.cmd, tool.options...); err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold(tool.name), style.Red.Regular("there are some errors in"), ":", style.Magenta.Bold(path)) msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold(tool.name), style.Red.Regular("there are some errors in"), ":", style.Magenta.Bold(path))
out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: tool.name, Stream: stream} out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: tool.name, Stream: stream}
p.stamp("error", out, msg, stream) p.stamp("error", out, msg, stream)