diff --git a/commands/root.go b/commands/root.go index 495e7014..7195d0d3 100644 --- a/commands/root.go +++ b/commands/root.go @@ -20,6 +20,7 @@ package commands import ( + "os" "os/exec" "path/filepath" @@ -184,5 +185,23 @@ func getProjectDir(dir string) (string, error) { return "", err } - return filepath.EvalSymlinks(dir) + dir, err = filepath.EvalSymlinks(dir) + if err != nil { + return "", err + } + + for { + f, err := os.Stat(filepath.Join(dir, ".git")) + if err == nil && f.IsDir() { + return dir, nil + } + + upDir := filepath.Dir(dir) + if upDir == dir || upDir == "." { + break + } + dir = upDir + } + + return "", errors.New("No project found") } diff --git a/envs/local.go b/envs/local.go index b687f7c8..34cb2664 100644 --- a/envs/local.go +++ b/envs/local.go @@ -47,8 +47,9 @@ func NewLocal(path string, debug bool) (*Local, error) { if err != nil { return nil, errors.WithStack(err) } + return &Local{ - Dir: guessProjectDir(path), + Dir: path, Debug: debug, }, nil } @@ -283,20 +284,3 @@ func (l *Local) webServer() Envs { return env } - -func guessProjectDir(dir string) string { - for { - f, err := os.Stat(filepath.Join(dir, ".git")) - if err == nil && f.IsDir() { - return dir - } - - upDir := filepath.Dir(dir) - if upDir == dir || upDir == "." { - break - } - dir = upDir - } - - return "" -} diff --git a/local/php/symfony.go b/local/php/symfony.go index 14e83c22..4ae705f0 100644 --- a/local/php/symfony.go +++ b/local/php/symfony.go @@ -4,24 +4,34 @@ import ( "os" "github.com/pkg/errors" + "path/filepath" ) // ComposerExecutor returns an Executor prepared to run Symfony Console. // It returns an error if no console binary is found. func SymonyConsoleExecutor(args []string) (*Executor, error) { - consolePath := "bin/console" + dir, err := os.Getwd() + if err != nil { + return nil, errors.WithStack(err) + } - if _, err := os.Stat(consolePath); err != nil { - // Fallback to app/console for projects created with older versions of Symfony - consolePath = "app/console" + for { + for _, consolePath := range []string{"bin/console", "app/console"} { + consolePath = filepath.Join(dir, consolePath) + if _, err := os.Stat(consolePath); err == nil { + return &Executor{ + BinName: "php", + Args: append([]string{"php", consolePath}, args...), + }, nil + } + } - if _, err2 := os.Stat(consolePath); err2 != nil { - return nil, errors.WithStack(err) + upDir := filepath.Dir(dir) + if upDir == dir || upDir == "." { + break } + dir = upDir } - return &Executor{ - BinName: "php", - Args: append([]string{"php", consolePath}, args...), - }, nil + return nil, errors.New("No console binary found") }