This commit is contained in:
asoseil 2018-04-14 16:15:03 +02:00
parent 600b1ac467
commit f0e28d1602
4 changed files with 19 additions and 14 deletions

View File

@ -1,8 +1,8 @@
package main package main
import ( import (
"github.com/tockins/interact" "github.com/oxequa/interact"
"github.com/tockins/realize/realize" "github.com/oxequa/realize/realize"
"gopkg.in/urfave/cli.v2" "gopkg.in/urfave/cli.v2"
"log" "log"
"os" "os"

View File

@ -26,7 +26,7 @@ var (
// Watch info // Watch info
type Watch struct { type Watch struct {
Exts []string `yaml:"exts" json:"exts"` Exts []string `yaml:"extensions" json:"extensions"`
Paths []string `yaml:"paths" json:"paths"` Paths []string `yaml:"paths" json:"paths"`
Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"` Scripts []Command `yaml:"scripts,omitempty" json:"scripts,omitempty"`
Hidden bool `yaml:"hidden,omitempty" json:"hidden,omitempty"` Hidden bool `yaml:"hidden,omitempty" json:"hidden,omitempty"`
@ -40,7 +40,7 @@ type Ignore struct{
// Command fields // Command fields
type Command struct { type Command struct {
Cmd string `yaml:"cmd" json:"cmd"` Cmd string `yaml:"command" json:"command"`
Type string `yaml:"type" json:"type"` Type string `yaml:"type" json:"type"`
Path string `yaml:"path,omitempty" json:"path,omitempty"` Path string `yaml:"path,omitempty" json:"path,omitempty"`
Global bool `yaml:"global,omitempty" json:"global,omitempty"` Global bool `yaml:"global,omitempty" json:"global,omitempty"`
@ -62,7 +62,7 @@ type Project struct {
Path string `yaml:"path" json:"path"` Path string `yaml:"path" json:"path"`
Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"` Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
Args []string `yaml:"args,omitempty" json:"args,omitempty"` Args []string `yaml:"args,omitempty" json:"args,omitempty"`
Tools Tools `yaml:"tools" json:"tools"` Tools Tools `yaml:"commands" json:"commands"`
Watcher Watch `yaml:"watcher" json:"watcher"` Watcher Watch `yaml:"watcher" json:"watcher"`
Buffer Buffer `yaml:"-" json:"buffer"` Buffer Buffer `yaml:"-" json:"buffer"`
ErrPattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"` ErrPattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"`
@ -196,7 +196,7 @@ 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(filepath.Dir(path)) fi, err := os.Stat(path)
if filepath.Ext(path) == "" { if filepath.Ext(path) == "" {
fi, err = os.Stat(path) fi, err = os.Stat(path)
} }
@ -477,8 +477,8 @@ func (p *Project) cmd(stop <-chan bool, flag string, global bool) {
case <-done: case <-done:
return return
case r := <-result: case r := <-result:
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold("Command"), Green.Bold("\"")+r.Name+Green.Bold("\"")) msg = fmt.Sprintln(p.pname(p.Name, 5), ":", Green.Bold("Command"), Green.Bold("\"")+r.Name+Green.Bold("\""))
if r.Err != nil { if r.Err != nil {
out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: flag} out = BufferOut{Time: time.Now(), Text: r.Err.Error(), Type: flag}
p.stamp("error", out, msg, fmt.Sprint(Red.Regular(r.Err.Error()))) p.stamp("error", out, msg, fmt.Sprint(Red.Regular(r.Err.Error())))
} else { } else {
@ -497,9 +497,9 @@ func (p *Project) walk(path string, info os.FileInfo, err error) error {
if p.parent.Settings.Recovery.Index { if p.parent.Settings.Recovery.Index {
log.Println("Indexing",path) log.Println("Indexing",path)
} }
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
@ -544,7 +544,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
log.Print(msg) log.Print(msg)
} }
if stream != "" { if stream != "" {
fmt.Fprint(Output, stream) fmt.Fprintln(Output, stream)
} }
go func() { go func() {
p.parent.Sync <- "sync" p.parent.Sync <- "sync"

View File

@ -43,7 +43,7 @@ func (t *Tools) Setup() {
if t.Clean.Status { if t.Clean.Status {
t.Clean.name = "Clean" t.Clean.name = "Clean"
t.Clean.isTool = true t.Clean.isTool = true
t.Clean.cmd = replace([]string{"go clean"}, t.Clean.Method) t.Clean.cmd = replace([]string{"go", "clean"}, t.Clean.Method)
t.Clean.Args = split([]string{}, t.Clean.Args) t.Clean.Args = split([]string{}, t.Clean.Args)
} }
// go generate // go generate
@ -134,7 +134,12 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
cmd.Stdout = &out cmd.Stdout = &out
cmd.Stderr = &stderr cmd.Stderr = &stderr
// Start command // Start command
cmd.Start() err := cmd.Start()
if err != nil{
response.Name = t.name
response.Err = err
return
}
go func() { done <- cmd.Wait() }() go func() { done <- cmd.Wait() }()
// Wait a result // Wait a result
select { select {
@ -145,7 +150,7 @@ func (t *Tool) Exec(path string, stop <-chan bool) (response Response) {
// Command completed // Command completed
response.Name = t.name response.Name = t.name
if err != nil { if err != nil {
response.Err = errors.New(stderr.String() + out.String()) response.Err = errors.New(stderr.String() + out.String() + err.Error())
} else { } else {
if t.Output { if t.Output {
response.Out = out.String() response.Out = out.String()

View File

@ -3,7 +3,7 @@ package main
import ( import (
"bytes" "bytes"
"errors" "errors"
"github.com/tockins/realize/realize" "github.com/oxequa/realize/realize"
"log" "log"
"strings" "strings"
"testing" "testing"