Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bee generate routers command #762

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cmd/commands/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ var CmdGenerate = &commands.Command{

$ bee generate docs

▶ {{"To generate swagger doc file:"|bold}}

$ bee generate routers [-ctrlDir=/path/to/controller/directory] [-routersFile=/path/to/routers/file.go] [-routersPkg=myPackage]

▶ {{"To generate a test case:"|bold}}

$ bee generate test [routerfile]
Expand All @@ -72,6 +76,15 @@ func init() {
CmdGenerate.Flag.Var(&generate.Level, "level", "Either 1, 2 or 3. i.e. 1=models; 2=models and controllers; 3=models, controllers and routers.")
CmdGenerate.Flag.Var(&generate.Fields, "fields", "List of table Fields.")
CmdGenerate.Flag.Var(&generate.DDL, "ddl", "Generate DDL Migration")

// bee generate routers
CmdGenerate.Flag.Var(&generate.ControllerDirectory, "ctrlDir",
"Controller directory. Bee scans this directory and its sub directory to generate routers")
CmdGenerate.Flag.Var(&generate.RoutersFile, "routersFile",
"Routers file. If not found, Bee create a new one. Bee will truncates this file and output routers info into this file")
CmdGenerate.Flag.Var(&generate.RouterPkg, "routersPkg",
`router's package. Default is routers, it means that "package routers" in the generated file`)

commands.AvailableCommands = append(commands.AvailableCommands, CmdGenerate)
}

Expand All @@ -97,13 +110,25 @@ func GenerateCode(cmd *commands.Command, args []string) int {
model(cmd, args, currpath)
case "view":
view(args, currpath)
case "routers":
genRouters(cmd, args)
default:
beeLogger.Log.Fatal("Command is missing")
}
beeLogger.Log.Successf("%s successfully generated!", strings.Title(gcmd))
return 0
}

func genRouters(cmd *commands.Command, args []string) {
err := cmd.Flag.Parse(args[1:])
beeLogger.Log.Infof("input parameter: %v", args)
if err != nil {
beeLogger.Log.Errorf("could not parse input parameter: %+v", err)
return
}
generate.GenRouters()
}

func scaffold(cmd *commands.Command, args []string, currpath string) {
if len(args) < 2 {
beeLogger.Log.Fatal("Wrong number of arguments. Run: bee help generate")
Expand Down
6 changes: 6 additions & 0 deletions generate/g.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ var Level utils.DocValue
var Tables utils.DocValue
var Fields utils.DocValue
var DDL utils.DocValue


// bee generate routers
var ControllerDirectory utils.DocValue
var RoutersFile utils.DocValue
var RouterPkg utils.DocValue
Loading