mirror of
https://github.com/beego/bee.git
synced 2024-11-23 06:40:54 +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
|
||||
example: bee generate scaffold post -fields="title:string,body:text"
|
||||
|
||||
bee generate model [modelname] [-fields=""]
|
||||
generate RESTFul model based on fields
|
||||
bee generate structure [structurename]
|
||||
generate struct based
|
||||
|
||||
bee generate structure [structurename] [-fields=""]
|
||||
generate struct based on fields
|
||||
-fields: a list of table fields. Format: field:type, ...
|
||||
|
||||
bee generate structure [structurefile] [-fields=""]
|
||||
generate struct based
|
||||
bee generate model [modelname]
|
||||
generate RESTFul model based
|
||||
|
||||
bee generate model [modelname] [-fields=""]
|
||||
generate RESTFul model based on fields
|
||||
-fields: a list of table fields. Format: field:type, ...
|
||||
|
||||
bee generate controller [controllerfile]
|
||||
@ -205,24 +211,28 @@ func generateCode(cmd *Command, args []string) int {
|
||||
|
||||
}
|
||||
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("[HINT] Usage: bee generate model [modelname] [-fields=\"\"]\n")
|
||||
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":
|
||||
if len(args) == 2 {
|
||||
cname := args[1]
|
||||
generateView(cname, curpath)
|
||||
vname := args[1]
|
||||
generateView(vname, curpath)
|
||||
} else {
|
||||
ColorLog("[ERRO] Wrong number of arguments\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)
|
||||
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)
|
||||
if hastime {
|
||||
content = strings.Replace(content, "{{timePkg}}", `"time"`, -1)
|
||||
content = strings.Replace(content, "{{timePkg}}", `import("time")`, -1)
|
||||
} else {
|
||||
content = strings.Replace(content, "{{timePkg}}", "", -1)
|
||||
}
|
||||
|
||||
} 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)
|
||||
f.WriteString(content)
|
||||
@ -136,14 +136,16 @@ func getType(ktype string) (kt, tag string, hasTime bool) {
|
||||
}
|
||||
|
||||
const (
|
||||
STRUCTURE_TPL = `package {{packageName}}
|
||||
BAST_STRUCTURE_TPL = `package {{packageName}}
|
||||
|
||||
type {{structureName}}Struct struct {
|
||||
|
||||
}
|
||||
`
|
||||
|
||||
INIT_STRUCTURE_TPL = `package {{packageName}}
|
||||
STRUCTURE_TPL = `package {{packageName}}
|
||||
|
||||
{{timePkg}}
|
||||
|
||||
{{structStruct}}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user