From 1f6e89a670b30d60a6a26e0a8557be9dc49280fc Mon Sep 17 00:00:00 2001 From: Back Yu Date: Tue, 7 Mar 2017 12:56:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=85=81=E8=AE=B8run=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E4=BD=BF=E7=94=A8extra=E5=8F=82=E6=95=B0=EF=BC=8Cwatch?= =?UTF-8?q?=E9=A2=9D=E5=A4=96=E7=9A=84package=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/run.go b/run.go index ba8af0c..54cc9d5 100644 --- a/run.go +++ b/run.go @@ -23,7 +23,7 @@ import ( ) 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] [-extra=extraPackageToWatch] [-tags=goBuildTags] [-runmode=BEEGO_RUNMODE]", Short: "Run the application by starting a local development server", Long: ` Run command will supervise the filesystem of the application for any changes, and recompile/restart it. @@ -53,6 +53,8 @@ var ( currentGoPath string // Current runmode runmode string + // Extra directories + extraPackages strFlags ) func init() { @@ -63,13 +65,13 @@ func init() { 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(&runmode, "runmode", "", "Set the Beego run mode.") + cmdRun.Flag.Var(&extraPackages, "extra", "List of extra package to watch.") exit = make(chan bool) } func runApp(cmd *Command, args []string) int { if len(args) == 0 || args[0] == "watchall" { currpath, _ = os.Getwd() - if found, _gopath, _ := SearchGOPATHs(currpath); found { appname = path.Base(currpath) currentGoPath = _gopath @@ -123,6 +125,30 @@ func runApp(cmd *Command, args []string) int { 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 { + logger.Warnf("%v", _fullPath) + readAppDirectories(_fullPath, &paths) + logger.Warnf("%v", 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{} for _, arg := range mainFiles { if len(arg) > 0 { From cc74358320fc0c86db64ceda6f6dfa1cd1c55676 Mon Sep 17 00:00:00 2001 From: Back Yu Date: Tue, 7 Mar 2017 13:00:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=AE=80=E5=8C=96=E5=8F=82=E6=95=B0extra?= =?UTF-8?q?=E4=B8=BAex=EF=BC=8C=E5=B9=B6=E7=A7=BB=E9=99=A4=E4=BA=86?= =?UTF-8?q?=E5=A4=9A=E4=BA=8E=E7=9A=84=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- run.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/run.go b/run.go index 54cc9d5..267b3f4 100644 --- a/run.go +++ b/run.go @@ -23,7 +23,7 @@ import ( ) var cmdRun = &Command{ - UsageLine: "run [appname] [watchall] [-main=*.go] [-downdoc=true] [-gendoc=true] [-vendor=true] [-e=folderToExclude] [-extra=extraPackageToWatch] [-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", Long: ` Run command will supervise the filesystem of the application for any changes, and recompile/restart it. @@ -65,7 +65,7 @@ func init() { 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(&runmode, "runmode", "", "Set the Beego run mode.") - cmdRun.Flag.Var(&extraPackages, "extra", "List of extra package to watch.") + cmdRun.Flag.Var(&extraPackages, "ex", "List of extra package to watch.") exit = make(chan bool) } @@ -129,9 +129,7 @@ func runApp(cmd *Command, args []string) int { // get the full path for _, packagePath := range extraPackages { if found, _, _fullPath := SearchGOPATHs(packagePath); found { - logger.Warnf("%v", _fullPath) readAppDirectories(_fullPath, &paths) - logger.Warnf("%v", paths) } else { logger.Warnf("No extra package '%s' found in your GOPATH", packagePath) }