mirror of
https://github.com/beego/bee.git
synced 2024-11-22 10:10:53 +00:00
Added check for multiple paths in GOPATH (instead of the first path in the list)
This commit is contained in:
parent
24955fb044
commit
5bc1c82a2b
32
run.go
32
run.go
@ -49,6 +49,8 @@ var (
|
||||
exit chan bool
|
||||
// Flag to watch the vendor folder
|
||||
vendorWatch bool
|
||||
// Current user workspace
|
||||
currentGoPath string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -65,26 +67,24 @@ func init() {
|
||||
func runApp(cmd *Command, args []string) int {
|
||||
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" {
|
||||
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)
|
||||
ColorLog("[INFO] Uses '%s' as 'appname'\n", appname)
|
||||
} else {
|
||||
gopathsrc := path.Join(gopath, "src")
|
||||
currpath = path.Join(gopathsrc, args[0])
|
||||
appname = path.Base(currpath)
|
||||
|
||||
// Check if passed Bee application path/name exists
|
||||
// in $GOPATH/src workspace
|
||||
if !isExist(currpath) {
|
||||
panic(fmt.Sprintf("No Beego application '%s' found in GOPATH: %s", args[0], gopathsrc))
|
||||
// Check if passed Bee application path/name exists in the GOPATH(s)
|
||||
if ok, _gopath, _path := SearchGOPATHs(args[0]); ok {
|
||||
currpath = _path
|
||||
currentGoPath = _gopath
|
||||
appname = path.Base(currpath)
|
||||
} else {
|
||||
panic(fmt.Sprintf("No Beego application '%s' found in your GOPATH", args[0]))
|
||||
}
|
||||
|
||||
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
|
||||
// and ignore non-go files.
|
||||
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{}
|
||||
|
31
util.go
31
util.go
@ -15,13 +15,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
"path"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Go is a basic promise implementation: it wraps calls a function in a goroutine
|
||||
@ -173,6 +174,34 @@ func GetGOPATHs() []string {
|
||||
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
|
||||
// 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
|
||||
|
Loading…
Reference in New Issue
Block a user