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

Merge pull request #121 from lei-cao/master

Issue-119: flags for excluding Godeps.
This commit is contained in:
astaxie 2015-06-17 15:32:00 +08:00
commit 6c98bdfbbc
2 changed files with 33 additions and 1 deletions

22
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]", UsageLine: "run [appname] [watchall] [-main=*.go] [-downdoc=true] [-gendoc=true] [-e=Godeps -e=folderToExclude]",
Short: "run the app and start a Web server for development", Short: "run the app and start a Web server for development",
Long: ` Long: `
Run command will supervise the file system of the beego project using inotify, Run command will supervise the file system of the beego project using inotify,
@ -37,11 +37,15 @@ var mainFiles ListOpts
var downdoc docValue var downdoc docValue
var gendoc docValue var gendoc docValue
// The flags list of the paths excluded from watching
var excludedPaths strFlags
func init() { func init() {
cmdRun.Run = runApp cmdRun.Run = runApp
cmdRun.Flag.Var(&mainFiles, "main", "specify main go files") cmdRun.Flag.Var(&mainFiles, "main", "specify main go files")
cmdRun.Flag.Var(&gendoc, "gendoc", "auto generate the docs") cmdRun.Flag.Var(&gendoc, "gendoc", "auto generate the docs")
cmdRun.Flag.Var(&downdoc, "downdoc", "auto download swagger file when not exist") cmdRun.Flag.Var(&downdoc, "downdoc", "auto download swagger file when not exist")
cmdRun.Flag.Var(&excludedPaths, "e", "Excluded paths[].")
} }
var appname string var appname string
@ -129,6 +133,11 @@ func readAppDirectories(directory string, paths *[]string) {
if strings.HasSuffix(fileInfo.Name(), "docs") { if strings.HasSuffix(fileInfo.Name(), "docs") {
continue continue
} }
if isExcluded(fileInfo) {
continue
}
if fileInfo.IsDir() == true && fileInfo.Name()[0] != '.' { if fileInfo.IsDir() == true && fileInfo.Name()[0] != '.' {
readAppDirectories(directory+"/"+fileInfo.Name(), paths) readAppDirectories(directory+"/"+fileInfo.Name(), paths)
continue continue
@ -146,3 +155,14 @@ func readAppDirectories(directory string, paths *[]string) {
return return
} }
// If a file is excluded
func isExcluded(fileInfo os.FileInfo) bool {
for _, p := range excludedPaths {
if strings.HasSuffix(fileInfo.Name(), p) {
ColorLog("[INFO] Excluding from watching [ %s ]\n", fileInfo.Name())
return true
}
}
return false
}

12
util.go
View File

@ -247,3 +247,15 @@ func camelString(s string) string {
} }
return string(data[:len(data)]) return string(data[:len(data)])
} }
// The string flag list, implemented flag.Value interface
type strFlags []string
func (s *strFlags) String() string {
return fmt.Sprintf("%d", *s)
}
func (s *strFlags) Set(value string) error {
*s = append(*s, value)
return nil
}