From 60e4f1b872255d3b78fa6ac08af419a85177c9b1 Mon Sep 17 00:00:00 2001 From: Lei Cao Date: Wed, 17 Jun 2015 14:59:59 +0800 Subject: [PATCH] Issue-119: flags for excluding Godeps. --- run.go | 22 +++++++++++++++++++++- util.go | 12 ++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/run.go b/run.go index 6563824..8d2f9a2 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]", + 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 +} diff --git a/util.go b/util.go index 02b2300..1b8685d 100644 --- a/util.go +++ b/util.go @@ -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 +}