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

Issue-119: flags for excluding Godeps.

This commit is contained in:
Lei Cao 2015-06-17 14:59:59 +08:00
parent 0c2ed7a9a4
commit 60e4f1b872
2 changed files with 33 additions and 1 deletions

22
run.go
View File

@ -23,7 +23,7 @@ import (
)
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",
Long: `
Run command will supervise the file system of the beego project using inotify,
@ -37,11 +37,15 @@ var mainFiles ListOpts
var downdoc docValue
var gendoc docValue
// The flags list of the paths excluded from watching
var excludedPaths strFlags
func init() {
cmdRun.Run = runApp
cmdRun.Flag.Var(&mainFiles, "main", "specify main go files")
cmdRun.Flag.Var(&gendoc, "gendoc", "auto generate the docs")
cmdRun.Flag.Var(&downdoc, "downdoc", "auto download swagger file when not exist")
cmdRun.Flag.Var(&excludedPaths, "e", "Excluded paths[].")
}
var appname string
@ -129,6 +133,11 @@ func readAppDirectories(directory string, paths *[]string) {
if strings.HasSuffix(fileInfo.Name(), "docs") {
continue
}
if isExcluded(fileInfo) {
continue
}
if fileInfo.IsDir() == true && fileInfo.Name()[0] != '.' {
readAppDirectories(directory+"/"+fileInfo.Name(), paths)
continue
@ -146,3 +155,14 @@ func readAppDirectories(directory string, paths *[]string) {
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)])
}
// 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
}