1
0
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:
MingZong 2016-04-01 00:32:47 +08:00
parent 52accaf1bd
commit 2106cf4a38
2 changed files with 33 additions and 21 deletions

38
g.go
View File

@ -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]
ColorLog("[ERRO] Wrong number of arguments\n") switch len(args) {
ColorLog("[HINT] Usage: bee generate model [modelname] [-fields=\"\"]\n") case 2:
os.Exit(2) generateModel(mname, "", curpath)
} case 3:
cmd.Flag.Parse(args[2:]) cmd.Flag.Parse(args[2:])
if fields == "" { if fields == "" {
ColorLog("[ERRO] Wrong number of arguments\n") ColorLog("[ERRO] Wrong number of arguments\n")
ColorLog("[HINT] Usage: bee generate model [modelname] [-fields=\"title:string,body:text\"]\n") ColorLog("[HINT] Usage: bee generate model [modelname] [-fields=\"title:string,body:text\"]\n")
os.Exit(2) os.Exit(2)
} }
sname := args[1] ColorLog("[INFO] Using '%s' as model name\n", mname)
ColorLog("[INFO] Using '%s' as model name\n", sname) generateModel(mname, fields.String(), curpath)
generateModel(sname, fields.String(), curpath) default:
ColorLog("[ERRO] Wrong number of arguments\n")
ColorLog("[HINT] Usage: bee generate model [modelname] [-fields=\"\"]\n")
os.Exit(2)
}
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")

View File

@ -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}}