1
0
mirror of https://github.com/beego/bee.git synced 2024-11-24 13:30:53 +00:00

Merge pull request #364 from szyhf/master

给bee run增加了一个参数extra,允许watch额外的包(刚忘了要pr到develop)
This commit is contained in:
astaxie 2017-03-08 11:30:24 +08:00 committed by GitHub
commit 9db35a8270

28
run.go
View File

@ -23,7 +23,7 @@ import (
) )
var cmdRun = &Command{ var cmdRun = &Command{
UsageLine: "run [appname] [watchall] [-main=*.go] [-downdoc=true] [-gendoc=true] [-vendor=true] [-e=folderToExclude] [-tags=goBuildTags] [-runmode=BEEGO_RUNMODE]", UsageLine: "run [appname] [watchall] [-main=*.go] [-downdoc=true] [-gendoc=true] [-vendor=true] [-e=folderToExclude] [-ex=extraPackageToWatch] [-tags=goBuildTags] [-runmode=BEEGO_RUNMODE]",
Short: "Run the application by starting a local development server", Short: "Run the application by starting a local development server",
Long: ` Long: `
Run command will supervise the filesystem of the application for any changes, and recompile/restart it. Run command will supervise the filesystem of the application for any changes, and recompile/restart it.
@ -53,6 +53,8 @@ var (
currentGoPath string currentGoPath string
// Current runmode // Current runmode
runmode string runmode string
// Extra directories
extraPackages strFlags
) )
func init() { func init() {
@ -63,13 +65,13 @@ func init() {
cmdRun.Flag.BoolVar(&vendorWatch, "vendor", false, "Enable watch vendor folder.") cmdRun.Flag.BoolVar(&vendorWatch, "vendor", false, "Enable watch vendor folder.")
cmdRun.Flag.StringVar(&buildTags, "tags", "", "Set the build tags. See: https://golang.org/pkg/go/build/") cmdRun.Flag.StringVar(&buildTags, "tags", "", "Set the build tags. See: https://golang.org/pkg/go/build/")
cmdRun.Flag.StringVar(&runmode, "runmode", "", "Set the Beego run mode.") cmdRun.Flag.StringVar(&runmode, "runmode", "", "Set the Beego run mode.")
cmdRun.Flag.Var(&extraPackages, "ex", "List of extra package to watch.")
exit = make(chan bool) exit = make(chan bool)
} }
func runApp(cmd *Command, args []string) int { func runApp(cmd *Command, args []string) int {
if len(args) == 0 || args[0] == "watchall" { if len(args) == 0 || args[0] == "watchall" {
currpath, _ = os.Getwd() currpath, _ = os.Getwd()
if found, _gopath, _ := SearchGOPATHs(currpath); found { if found, _gopath, _ := SearchGOPATHs(currpath); found {
appname = path.Base(currpath) appname = path.Base(currpath)
currentGoPath = _gopath currentGoPath = _gopath
@ -123,6 +125,28 @@ func runApp(cmd *Command, args []string) int {
paths = append(paths, strings.Replace(p, "$GOPATH", currentGoPath, -1)) paths = append(paths, strings.Replace(p, "$GOPATH", currentGoPath, -1))
} }
if len(extraPackages) > 0 {
// get the full path
for _, packagePath := range extraPackages {
if found, _, _fullPath := SearchGOPATHs(packagePath); found {
readAppDirectories(_fullPath, &paths)
} else {
logger.Warnf("No extra package '%s' found in your GOPATH", packagePath)
}
}
// let paths unique
strSet := make(map[string]struct{})
for _, p := range paths {
strSet[p] = struct{}{}
}
paths = make([]string, len(strSet))
index := 0
for i := range strSet {
paths[index] = i
index++
}
}
files := []string{} files := []string{}
for _, arg := range mainFiles { for _, arg := range mainFiles {
if len(arg) > 0 { if len(arg) > 0 {