Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Fixed issue #203: multiple GOPATH are not supported by buffalo new. #205

Merged
merged 2 commits into from
Feb 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions buffalo/cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"os"
"os/user"
"path/filepath"
"runtime"
"strings"

"github.com/gobuffalo/envy"
Expand Down Expand Up @@ -93,7 +94,24 @@ func validateInGoPath(name string) error {
return err
}

if !strings.HasPrefix(root, filepath.Join(gp, "src")) {
var gpMultiple []string

if runtime.GOOS == "windows" {
gpMultiple = strings.Split(gp, ";") // Windows uses a different separator
} else {
gpMultiple = strings.Split(gp, ":")
}
gpMultipleLen := len(gpMultiple)
foundInPath := false

for i := 0; i < gpMultipleLen; i++ {
if strings.HasPrefix(root, filepath.Join(gpMultiple[i], "src")) {
foundInPath = true
break
}
}

if !foundInPath {
u, err := user.Current()
if err != nil {
return err
Expand All @@ -113,6 +131,27 @@ func validateInGoPath(name string) error {
return nil
}

func goPath(root string) string {
var gpMultiple []string
gp := os.Getenv("GOPATH")

if runtime.GOOS == "windows" {
gpMultiple = strings.Split(gp, ";") // Windows uses a different separator
} else {
gpMultiple = strings.Split(gp, ":")
}
gpMultipleLen := len(gpMultiple)
path := ""

for i := 0; i < gpMultipleLen; i++ {
if strings.HasPrefix(root, filepath.Join(gpMultiple[i], "src")) {
path = gpMultiple[i]
break
}
}
return path
}

func rootPath(name string) (string, error) {
pwd, err := os.Getwd()
if err != nil {
Expand All @@ -123,7 +162,7 @@ func rootPath(name string) (string, error) {
}

func packagePath(rootPath string) string {
gosrcpath := strings.Replace(filepath.Join(os.Getenv("GOPATH"), "src"), "\\", "/", -1)
gosrcpath := strings.Replace(filepath.Join(goPath(rootPath), "src"), "\\", "/", -1)
rootPath = strings.Replace(rootPath, "\\", "/", -1)
return strings.Replace(rootPath, gosrcpath+"/", "", 2)
}
Expand Down