Skip to content

Commit

Permalink
#118 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
asoseil committed Nov 14, 2017
1 parent 49b5748 commit cf97995
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
21 changes: 8 additions & 13 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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"),
Expand Down
8 changes: 5 additions & 3 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf97995

Please sign in to comment.