mirror of
https://github.com/beego/bee.git
synced 2024-11-23 11:50:55 +00:00
Change Description and Change the words
This commit is contained in:
parent
52accaf1bd
commit
2106cf4a38
42
g.go
42
g.go
@ -27,12 +27,18 @@ bee generate scaffold [scaffoldname] [-fields=""] [-driver=mysql] [-conn="root:@
|
|||||||
-conn: the connection string used by the driver, the default is root:@tcp(127.0.0.1:3306)/test
|
-conn: the connection string used by the driver, the default is root:@tcp(127.0.0.1:3306)/test
|
||||||
example: bee generate scaffold post -fields="title:string,body:text"
|
example: bee generate scaffold post -fields="title:string,body:text"
|
||||||
|
|
||||||
bee generate model [modelname] [-fields=""]
|
bee generate structure [structurename]
|
||||||
generate RESTFul model based on fields
|
generate struct based
|
||||||
|
|
||||||
|
bee generate structure [structurename] [-fields=""]
|
||||||
|
generate struct based on fields
|
||||||
-fields: a list of table fields. Format: field:type, ...
|
-fields: a list of table fields. Format: field:type, ...
|
||||||
|
|
||||||
bee generate structure [structurefile] [-fields=""]
|
bee generate model [modelname]
|
||||||
generate struct based
|
generate RESTFul model based
|
||||||
|
|
||||||
|
bee generate model [modelname] [-fields=""]
|
||||||
|
generate RESTFul model based on fields
|
||||||
-fields: a list of table fields. Format: field:type, ...
|
-fields: a list of table fields. Format: field:type, ...
|
||||||
|
|
||||||
bee generate controller [controllerfile]
|
bee generate controller [controllerfile]
|
||||||
@ -205,24 +211,28 @@ func generateCode(cmd *Command, args []string) int {
|
|||||||
|
|
||||||
}
|
}
|
||||||
case "model":
|
case "model":
|
||||||
if len(args) < 2 {
|
mname := args[1]
|
||||||
|
switch len(args) {
|
||||||
|
case 2:
|
||||||
|
generateModel(mname, "", curpath)
|
||||||
|
case 3:
|
||||||
|
cmd.Flag.Parse(args[2:])
|
||||||
|
if fields == "" {
|
||||||
|
ColorLog("[ERRO] Wrong number of arguments\n")
|
||||||
|
ColorLog("[HINT] Usage: bee generate model [modelname] [-fields=\"title:string,body:text\"]\n")
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
|
ColorLog("[INFO] Using '%s' as model name\n", mname)
|
||||||
|
generateModel(mname, fields.String(), curpath)
|
||||||
|
default:
|
||||||
ColorLog("[ERRO] Wrong number of arguments\n")
|
ColorLog("[ERRO] Wrong number of arguments\n")
|
||||||
ColorLog("[HINT] Usage: bee generate model [modelname] [-fields=\"\"]\n")
|
ColorLog("[HINT] Usage: bee generate model [modelname] [-fields=\"\"]\n")
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
cmd.Flag.Parse(args[2:])
|
|
||||||
if fields == "" {
|
|
||||||
ColorLog("[ERRO] Wrong number of arguments\n")
|
|
||||||
ColorLog("[HINT] Usage: bee generate model [modelname] [-fields=\"title:string,body:text\"]\n")
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
sname := args[1]
|
|
||||||
ColorLog("[INFO] Using '%s' as model name\n", sname)
|
|
||||||
generateModel(sname, fields.String(), curpath)
|
|
||||||
case "view":
|
case "view":
|
||||||
if len(args) == 2 {
|
if len(args) == 2 {
|
||||||
cname := args[1]
|
vname := args[1]
|
||||||
generateView(cname, curpath)
|
generateView(vname, curpath)
|
||||||
} else {
|
} else {
|
||||||
ColorLog("[ERRO] Wrong number of arguments\n")
|
ColorLog("[ERRO] Wrong number of arguments\n")
|
||||||
ColorLog("[HINT] Usage: bee generate view [viewpath]\n")
|
ColorLog("[HINT] Usage: bee generate view [viewpath]\n")
|
||||||
|
@ -50,16 +50,16 @@ func generateStructure(cname, fields, crupath string) {
|
|||||||
ColorLog("[ERRO] Could not genrate struct: %s\n", err)
|
ColorLog("[ERRO] Could not genrate struct: %s\n", err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
content = strings.Replace(INIT_STRUCTURE_TPL, "{{packageName}}", packageName, -1)
|
content = strings.Replace(STRUCTURE_TPL, "{{packageName}}", packageName, -1)
|
||||||
content = strings.Replace(content, "{{structStruct}}", structStruct, -1)
|
content = strings.Replace(content, "{{structStruct}}", structStruct, -1)
|
||||||
if hastime {
|
if hastime {
|
||||||
content = strings.Replace(content, "{{timePkg}}", `"time"`, -1)
|
content = strings.Replace(content, "{{timePkg}}", `import("time")`, -1)
|
||||||
} else {
|
} else {
|
||||||
content = strings.Replace(content, "{{timePkg}}", "", -1)
|
content = strings.Replace(content, "{{timePkg}}", "", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
content = strings.Replace(STRUCTURE_TPL, "{{packageName}}", packageName, -1)
|
content = strings.Replace(BAST_STRUCTURE_TPL, "{{packageName}}", packageName, -1)
|
||||||
}
|
}
|
||||||
content = strings.Replace(content, "{{structureName}}", structureName, -1)
|
content = strings.Replace(content, "{{structureName}}", structureName, -1)
|
||||||
f.WriteString(content)
|
f.WriteString(content)
|
||||||
@ -136,14 +136,16 @@ func getType(ktype string) (kt, tag string, hasTime bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
STRUCTURE_TPL = `package {{packageName}}
|
BAST_STRUCTURE_TPL = `package {{packageName}}
|
||||||
|
|
||||||
type {{structureName}}Struct struct {
|
type {{structureName}}Struct struct {
|
||||||
|
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
INIT_STRUCTURE_TPL = `package {{packageName}}
|
STRUCTURE_TPL = `package {{packageName}}
|
||||||
|
|
||||||
|
{{timePkg}}
|
||||||
|
|
||||||
{{structStruct}}
|
{{structStruct}}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user