mirror of
https://github.com/beego/bee.git
synced 2024-11-24 13:30:53 +00:00
getting params from commandline and hook up the actual function
This commit is contained in:
parent
0a22533e04
commit
8e56c8528f
20
g.go
20
g.go
@ -20,7 +20,7 @@ var cmdGenerate = &Command{
|
|||||||
UsageLine: "generate [Command]",
|
UsageLine: "generate [Command]",
|
||||||
Short: "generate code based on application",
|
Short: "generate code based on application",
|
||||||
Long: `
|
Long: `
|
||||||
bee generate model [modelfile] [dbconfig]
|
bee generate model driver [dbconfig]
|
||||||
generate model base on struct
|
generate model base on struct
|
||||||
bee generate controller [modelfile]
|
bee generate controller [modelfile]
|
||||||
generate RESTFul controllers based on modelfile
|
generate RESTFul controllers based on modelfile
|
||||||
@ -33,7 +33,19 @@ bee generate test [routerfile]
|
|||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var driver docValue
|
||||||
|
var conn docValue
|
||||||
|
var level docValue
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
cmdGenerate.Run = generateCode
|
||||||
|
cmdGenerate.Flag.Var(&driver, "driver", "database driver: mysql, postgresql, etc.")
|
||||||
|
cmdGenerate.Flag.Var(&conn, "conn", "connection string used by the driver to connect to a database instance")
|
||||||
|
cmdGenerate.Flag.Var(&level, "level", "1 = models only; 2 = models and controllers; 3 = models, controllers and routers")
|
||||||
|
}
|
||||||
|
|
||||||
func generateCode(cmd *Command, args []string) {
|
func generateCode(cmd *Command, args []string) {
|
||||||
|
cmd.Flag.Parse(args[1:])
|
||||||
curpath, _ := os.Getwd()
|
curpath, _ := os.Getwd()
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
ColorLog("[ERRO] command is missing\n")
|
ColorLog("[ERRO] command is missing\n")
|
||||||
@ -53,11 +65,7 @@ func generateCode(cmd *Command, args []string) {
|
|||||||
case "docs":
|
case "docs":
|
||||||
generateDocs(curpath)
|
generateDocs(curpath)
|
||||||
case "model":
|
case "model":
|
||||||
generateModel("mysql", "root@tcp(127.0.0.1:3306)/sgfas?charset=utf8", curpath)
|
generateModel(string(driver), string(conn), string(level), curpath)
|
||||||
case "controller":
|
|
||||||
generateController("mysql", "", curpath)
|
|
||||||
case "router":
|
|
||||||
generateRouter("mysql", "", curpath)
|
|
||||||
default:
|
default:
|
||||||
ColorLog("[ERRO] command is missing\n")
|
ColorLog("[ERRO] command is missing\n")
|
||||||
}
|
}
|
||||||
|
23
g_mvc.go
23
g_mvc.go
@ -177,18 +177,19 @@ func (tag *OrmTag) String() string {
|
|||||||
return fmt.Sprintf("`orm:\"%s\"`", strings.Join(ormOptions, ";"))
|
return fmt.Sprintf("`orm:\"%s\"`", strings.Join(ormOptions, ";"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateModel(driver string, connStr string, currpath string) {
|
func generateModel(driver string, connStr string, level string, currpath string) {
|
||||||
mode := O_MODEL
|
var mode byte
|
||||||
gen(driver, connStr, mode, currpath)
|
if level == "1" {
|
||||||
|
mode = O_MODEL
|
||||||
|
} else if level == "2" {
|
||||||
|
mode = O_MODEL | O_CONTROLLER
|
||||||
|
} else if level == "3" {
|
||||||
|
mode = O_MODEL | O_CONTROLLER | O_ROUTER
|
||||||
|
} else {
|
||||||
|
ColorLog("[ERRO] Invalid 'level' option: %s\n", level)
|
||||||
|
ColorLog("[HINT] Level must be either 1, 2 or 3\n")
|
||||||
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateController(driver string, connStr string, currpath string) {
|
|
||||||
mode := O_MODEL | O_CONTROLLER
|
|
||||||
gen(driver, connStr, mode, currpath)
|
|
||||||
}
|
|
||||||
|
|
||||||
func generateRouter(driver string, connStr string, currpath string) {
|
|
||||||
mode := O_MODEL | O_CONTROLLER | O_ROUTER
|
|
||||||
gen(driver, connStr, mode, currpath)
|
gen(driver, connStr, mode, currpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user