double path field fixed

This commit is contained in:
asoseil 2017-10-23 00:35:45 +02:00
parent 725783831f
commit 61d9efe90f
3 changed files with 18 additions and 18 deletions

12
cmd.go
View File

@ -7,6 +7,7 @@ import (
"path/filepath"
"time"
"reflect"
"fmt"
)
// Tool options customizable, should be moved in Cmd
@ -117,10 +118,11 @@ func (r *realize) run(p *cli.Context) error {
continue
}
// validate project path, if invalid get wdir or clean current
if !filepath.IsAbs(elm.path){
r.Schema[k].path = wdir()
if !filepath.IsAbs(elm.Path){
r.Schema[k].Path = wdir()
}else{
r.Schema[k].path = filepath.Clean(elm.path)
r.Schema[k].Path = filepath.Clean(elm.Path)
fmt.Println(r.Schema[k].Path )
}
// env variables
for key, item := range r.Schema[k].Environment {
@ -129,7 +131,7 @@ func (r *realize) run(p *cli.Context) error {
}
}
// get basepath name
r.Schema[k].name = filepath.Base(r.Schema[k].path)
r.Schema[k].name = filepath.Base(r.Schema[k].Path)
fields := reflect.Indirect(reflect.ValueOf(&r.Schema[k].Cmds))
// Loop struct Cmds fields
@ -210,9 +212,7 @@ func (r *realize) run(p *cli.Context) error {
startTxt: "Building...",
endTxt: "Built",
}
r.Schema[k].parent = r
r.Schema[k].path = r.Schema[k].Path
match = true
go r.Schema[k].watch()

12
exec.go
View File

@ -22,7 +22,7 @@ func (p *Project) goCompile(stop <-chan bool, method []string, args []string) (s
done := make(chan error)
args = append(method, args...)
cmd := exec.Command(args[0], args[1:]...)
cmd.Dir = p.path
cmd.Dir = p.Path
cmd.Stdout = &out
cmd.Stderr = &stderr
// Start command
@ -79,7 +79,7 @@ func (p *Project) goRun(stop <-chan bool, runner chan bool) {
} else if _, err := os.Stat(path + extWindows); err == nil {
build = exec.Command(path+extWindows, args...)
} else {
path := filepath.Join(p.path, p.name)
path := filepath.Join(p.Path, p.name)
if _, err = os.Stat(path); err == nil {
build = exec.Command(path, args...)
} else if _, err = os.Stat(path + extWindows); err == nil {
@ -150,13 +150,13 @@ func (p *Project) command(stop <-chan bool, cmd Command) (string, string) {
done := make(chan error)
args := strings.Split(strings.Replace(strings.Replace(cmd.Command, "'", "", -1), "\"", "", -1), " ")
exec := exec.Command(args[0], args[1:]...)
exec.Dir = p.path
exec.Dir = p.Path
// make cmd path
if cmd.Path != "" {
if strings.Contains(cmd.Path, p.path) {
if strings.Contains(cmd.Path, p.Path) {
exec.Dir = cmd.Path
} else {
exec.Dir = filepath.Join(p.path, cmd.Path)
exec.Dir = filepath.Join(p.Path, cmd.Path)
}
}
exec.Stdout = &stdout
@ -189,7 +189,7 @@ func (p *Project) goTool(wg *sync.WaitGroup, stop <-chan bool, result chan<- too
if strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "") {
if strings.HasSuffix(path, ".go") {
tool.options = append(tool.options, path)
path = p.path
path = p.Path
}
if s := ext(path); s == "" || s == "go" {
var out, stderr bytes.Buffer

View File

@ -55,7 +55,7 @@ type Project struct {
watcher FileWatcher
init bool
files, folders int64
name, path, lastFile string
name, lastFile string
tools []tool
paths []string
lastTime time.Time
@ -98,7 +98,7 @@ func (p *Project) watch() {
p.cmd(stop, "before", true)
// indexing files and dirs
for _, dir := range p.Watcher.Paths {
base := filepath.Join(p.path, dir)
base := filepath.Join(p.Path, dir)
if _, err := os.Stat(base); err == nil {
if err := filepath.Walk(base, p.walk); err == nil {
p.tool(stop, base)
@ -312,7 +312,7 @@ func (p *Project) changed(event fsnotify.Event, stop chan bool) {
// Watch the files tree of a project
func (p *Project) walk(path string, info os.FileInfo, err error) error {
for _, v := range p.Watcher.Ignore {
s := append([]string{p.path},strings.Split(v,string(os.PathSeparator))...)
s := append([]string{p.Path},strings.Split(v,string(os.PathSeparator))...)
if strings.Contains(path, filepath.Join(s...)) {
return nil
}
@ -339,7 +339,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
case "out":
p.Buffer.StdOut = append(p.Buffer.StdOut, o)
if p.Files.Outputs.Status {
f := p.create(p.path, p.Files.Outputs.Name)
f := p.create(p.Path, p.Files.Outputs.Name)
t := time.Now()
s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"}
if _, err := f.WriteString(strings.Join(s, " ")); err != nil {
@ -349,7 +349,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
case "log":
p.Buffer.StdLog = append(p.Buffer.StdLog, o)
if p.Files.Logs.Status {
f := p.create(p.path, p.Files.Logs.Name)
f := p.create(p.Path, p.Files.Logs.Name)
t := time.Now()
s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Text, "\r\n"}
if stream != "" {
@ -362,7 +362,7 @@ func (p *Project) stamp(t string, o BufferOut, msg string, stream string) {
case "error":
p.Buffer.StdErr = append(p.Buffer.StdErr, o)
if p.Files.Errors.Status {
f := p.create(p.path, p.Files.Errors.Name)
f := p.create(p.Path, p.Files.Errors.Name)
t := time.Now()
s := []string{t.Format("2006-01-02 15:04:05"), strings.ToUpper(p.Name), ":", o.Type, o.Text, o.Path, "\r\n"}
if stream != "" {