diff --git a/cmd/commands/generate/generate.go b/cmd/commands/generate/generate.go index d8bee28bc..1936b3c26 100644 --- a/cmd/commands/generate/generate.go +++ b/cmd/commands/generate/generate.go @@ -81,12 +81,30 @@ func GenerateCode(cmd *commands.Command, args []string) int { beeLogger.Log.Fatal("Command is missing") } + // get tags value + tagsIndex := -1 + for i, arg := range args { + if arg == "--tags" && i+1 < len(args) { + tagsIndex = i + 1 + break + } + } + var tags []string + if tagsIndex != -1 { + tags = strings.Split(args[tagsIndex], ",") + for i, str := range tags { + tags[i] = strings.TrimSpace(str) + } + } else { + tags = []string{} + } + gcmd := args[0] switch gcmd { case "scaffold": scaffold(cmd, args, currpath) case "docs": - swaggergen.GenerateDocs(currpath) + swaggergen.GenerateDocs(currpath, tags) case "appcode": appCode(cmd, args, currpath) case "migration": diff --git a/generate/swaggergen/g_docs.go b/generate/swaggergen/g_docs.go index f9cde93aa..d0bd67223 100644 --- a/generate/swaggergen/g_docs.go +++ b/generate/swaggergen/g_docs.go @@ -157,7 +157,7 @@ func parsePackageFromDir(path string) error { } // GenerateDocs generates documentations for a given path. -func GenerateDocs(curpath string) { +func GenerateDocs(curpath string, tags []string) { pkgspath := curpath workspace := os.Getenv("BeeWorkspace") if workspace != "" { @@ -272,6 +272,36 @@ func GenerateDocs(curpath string) { } analyseControllerPkg(localName, im.Path.Value) } + + // fileter the controllerList by tags + if len(tags)>0 { + for _, controllerValue := range controllerList { + for routerPath, item := range controllerValue { + var tags_ []string + if item.Get != nil { + tags_ = item.Get.Tags + } else { + tags_ = item.Post.Tags + } + isContained := false + for _, tag := range tags { + for _, tag_ := range tags_{ + if strings.EqualFold(tag, tag_) { + isContained = true + break + } + } + if isContained { + break + } + } + if !isContained { + delete(controllerValue, routerPath) + } + } + } + } + for _, d := range f.Decls { switch specDecl := d.(type) { case *ast.FuncDecl: