1
0
mirror of https://github.com/beego/bee.git synced 2024-11-24 13:30:53 +00:00
bee/g.go

46 lines
1.0 KiB
Go

package main
import "os"
var cmdGenerate = &Command{
UsageLine: "generate [Command]",
Short: "generate code based on application",
Long: `
bee g model [modelfile] [dbconfig]
generate model base on struct
bee g controller [modelfile]
generate RESTFul controllers based on modelfile
bee g router [controllerfile]
generate router based on controllerfile
bee g docs
generate swagger doc file
bee g test [routerfile]
generate testcase
`,
}
func generateCode(cmd *Command, args []string) {
curpath, _ := os.Getwd()
if len(args) < 1 {
ColorLog("[ERRO] command is missing\n")
os.Exit(2)
}
gopath := os.Getenv("GOPATH")
Debugf("gopath:%s", gopath)
if gopath == "" {
ColorLog("[ERRO] $GOPATH not found\n")
ColorLog("[HINT] Set $GOPATH in your environment vairables\n")
os.Exit(2)
}
gcmd := args[0]
switch gcmd {
case "docs":
generateDocs(curpath)
default:
ColorLog("[ERRO] command is missing\n")
}
ColorLog("[SUCC] generate successfully created!\n")
}