1
0
mirror of https://github.com/beego/bee.git synced 2024-11-22 15:10:54 +00:00

Added check for multiple paths in GOPATH (instead of the first path in the list)

This commit is contained in:
Faissal Elamraoui 2016-07-29 17:45:15 +02:00
parent 24955fb044
commit 5bc1c82a2b
2 changed files with 46 additions and 17 deletions

30
run.go
View File

@ -49,6 +49,8 @@ var (
exit chan bool exit chan bool
// Flag to watch the vendor folder // Flag to watch the vendor folder
vendorWatch bool vendorWatch bool
// Current user workspace
currentGoPath string
) )
func init() { func init() {
@ -65,26 +67,24 @@ func init() {
func runApp(cmd *Command, args []string) int { func runApp(cmd *Command, args []string) int {
ShowShortVersionBanner() ShowShortVersionBanner()
gps := GetGOPATHs()
if len(gps) == 0 {
ColorLog("[ERRO] Fail to start[ %s ]\n", "$GOPATH is not set or empty")
os.Exit(2)
}
gopath := gps[0]
if len(args) == 0 || args[0] == "watchall" { if len(args) == 0 || args[0] == "watchall" {
currpath, _ = os.Getwd() currpath, _ = os.Getwd()
if !isBeegoProject(currpath) {
exitPrint(fmt.Sprintf("Bee does not support non Beego project: %s", currpath))
}
_, currentGoPath, _ = SearchGOPATHs(currpath)
appname = path.Base(currpath) appname = path.Base(currpath)
ColorLog("[INFO] Uses '%s' as 'appname'\n", appname) ColorLog("[INFO] Uses '%s' as 'appname'\n", appname)
} else { } else {
gopathsrc := path.Join(gopath, "src") // Check if passed Bee application path/name exists in the GOPATH(s)
currpath = path.Join(gopathsrc, args[0]) if ok, _gopath, _path := SearchGOPATHs(args[0]); ok {
currpath = _path
currentGoPath = _gopath
appname = path.Base(currpath) appname = path.Base(currpath)
} else {
// Check if passed Bee application path/name exists panic(fmt.Sprintf("No Beego application '%s' found in your GOPATH", args[0]))
// in $GOPATH/src workspace
if !isExist(currpath) {
panic(fmt.Sprintf("No Beego application '%s' found in GOPATH: %s", args[0], gopathsrc))
} }
ColorLog("[INFO] Uses '%s' as 'appname'\n", appname) ColorLog("[INFO] Uses '%s' as 'appname'\n", appname)
@ -110,7 +110,7 @@ func runApp(cmd *Command, args []string) int {
// Because monitor files has some issues, we watch current directory // Because monitor files has some issues, we watch current directory
// and ignore non-go files. // and ignore non-go files.
for _, p := range conf.DirStruct.Others { for _, p := range conf.DirStruct.Others {
paths = append(paths, strings.Replace(p, "$GOPATH", gopath, -1)) paths = append(paths, strings.Replace(p, "$GOPATH", currentGoPath, -1))
} }
files := []string{} files := []string{}

31
util.go
View File

@ -15,13 +15,14 @@
package main package main
import ( import (
"fmt"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strings" "strings"
"time" "time"
"path"
"fmt"
) )
// Go is a basic promise implementation: it wraps calls a function in a goroutine // Go is a basic promise implementation: it wraps calls a function in a goroutine
@ -173,6 +174,34 @@ func GetGOPATHs() []string {
return paths return paths
} }
func SearchGOPATHs(app string) (bool, string, string) {
gps := GetGOPATHs()
if len(gps) == 0 {
ColorLog("[ERRO] Fail to start [ %s ]\n", "GOPATH environment variable is not set or empty")
os.Exit(2)
}
// Lookup the application inside the user workspace(s)
for _, gopath := range gps {
var currentPath string
if !strings.Contains(app, "src") {
gopathsrc := path.Join(gopath, "src")
currentPath = path.Join(gopathsrc, app)
} else {
currentPath = app
}
if isExist(currentPath) {
if !isBeegoProject(currentPath) {
continue
}
return true, gopath, currentPath
}
}
return false, "", ""
}
// askForConfirmation uses Scanln to parse user input. A user must type in "yes" or "no" and // askForConfirmation uses Scanln to parse user input. A user must type in "yes" or "no" and
// then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as // then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as
// confirmations. If the input is not recognized, it will ask again. The function does not return // confirmations. If the input is not recognized, it will ask again. The function does not return