From cf97995848e4e50cf94b3dfda6cf30e57c89ccc5 Mon Sep 17 00:00:00 2001 From: asoseil Date: Tue, 14 Nov 2017 19:17:34 +0100 Subject: [PATCH] #118 fixed --- cmd.go | 21 ++++++++------------- exec.go | 8 +++++--- watcher.go | 6 ------ 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/cmd.go b/cmd.go index 6ae1fb8..8a71296 100644 --- a/cmd.go +++ b/cmd.go @@ -43,6 +43,8 @@ func (r *realize) clean() error { arr := r.Schema for key, val := range arr { if _, err := duplicates(val, arr[key+1:]); err != nil { + // path validation + r.Schema = append(arr[:key], arr[key+1:]...) break } @@ -54,21 +56,14 @@ func (r *realize) clean() error { // Add a new project func (r *realize) add(p *cli.Context) (err error) { - var path string - // #118 get relative and if not exist try to get abs - if _, err = os.Stat(p.String("path")); os.IsNotExist(err) { - // path doesn't exist - path, err = filepath.Abs(p.String("path")) - if err != nil { - return err - } - } else { - path = filepath.Clean(p.String("path")) + // project init + name := filepath.Base(p.String("path")) + if name == "." { + name = filepath.Base(wdir()) } - project := Project{ - Name: filepath.Base(wdir()), - Path: path, + Name: name, + Path: p.String("path"), Cmds: Cmds{ Vet: Cmd{ Status: p.Bool("vet"), diff --git a/exec.go b/exec.go index de21a32..09c4615 100644 --- a/exec.go +++ b/exec.go @@ -48,7 +48,6 @@ func (p *Project) goCompile(stop <-chan bool, method []string, args []string) (s func (p *Project) goRun(stop <-chan bool, runner chan bool) { var build *exec.Cmd var args []string - // custom error pattern isErrorText := func(string) bool { return false @@ -73,13 +72,16 @@ func (p *Project) goRun(stop <-chan bool, runner chan bool) { } gobin := os.Getenv("GOBIN") - path := filepath.Join(gobin, p.name) + dirPath := filepath.Base(p.Path) + if p.Path == "." { + dirPath = filepath.Base(wdir()) + } + path := filepath.Join(gobin, dirPath) if _, err := os.Stat(path); err == nil { build = exec.Command(path, args...) } else if _, err := os.Stat(path + extWindows); err == nil { build = exec.Command(path+extWindows, args...) } else { - 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 { diff --git a/watcher.go b/watcher.go index d62674c..a53ba20 100644 --- a/watcher.go +++ b/watcher.go @@ -187,12 +187,6 @@ func (p *Project) err(err error) { // Config project init func (p *Project) config(r *realize) { - // validate project path, if invalid get wdir or clean current - if !filepath.IsAbs(p.Path) { - p.Path = wdir() - } else { - p.Path = filepath.Clean(p.Path) - } // get basepath name p.name = filepath.Base(p.Path) // env variables