mirror of
https://github.com/beego/bee.git
synced 2024-12-27 08:10:59 +00:00
Merge pull request #44 from ZhengYang/master
Loading JSON config and default value changes for generate appcode
This commit is contained in:
commit
9f80acc0ff
6
bee.json
6
bee.json
@ -13,5 +13,9 @@
|
||||
"others": []
|
||||
},
|
||||
"cmd_args": [],
|
||||
"envs": []
|
||||
"envs": [],
|
||||
"database": {
|
||||
"driver": "mysql",
|
||||
"conn": "root:@tcp(127.0.0.1:3306)/test"
|
||||
}
|
||||
}
|
10
conf.go
10
conf.go
@ -36,7 +36,11 @@ var defaultConf = `{
|
||||
"others": []
|
||||
},
|
||||
"cmd_args": [],
|
||||
"envs": []
|
||||
"envs": [],
|
||||
"database": {
|
||||
"driver": "mysql",
|
||||
"conn": "root:@tcp(127.0.0.1:3306)/test"
|
||||
}
|
||||
}
|
||||
`
|
||||
var conf struct {
|
||||
@ -62,6 +66,10 @@ var conf struct {
|
||||
Dirs []string
|
||||
IngExt []string `json:"ignore_ext"`
|
||||
}
|
||||
Database struct {
|
||||
Driver string
|
||||
Conn string
|
||||
}
|
||||
}
|
||||
|
||||
// loadConfig loads customized configuration.
|
||||
|
23
g.go
23
g.go
@ -43,12 +43,12 @@ bee generate docs
|
||||
bee generate test [routerfile]
|
||||
generate testcase
|
||||
|
||||
bee generate appcode [-tables=""] [-driver=mysql] [-conn=root:@tcp(127.0.0.1:3306)/test] [-level=1]
|
||||
bee generate appcode [-tables=""] [-driver=mysql] [-conn=root:@tcp(127.0.0.1:3306)/test] [-level=3]
|
||||
generate appcode based on an existing database
|
||||
-tables: a list of table names separated by ',', default is empty, indicating all tables
|
||||
-driver: [mysql | postgresql | sqlite], the default is mysql
|
||||
-conn: the connection string used by the driver, the default is root:@tcp(127.0.0.1:3306)/test
|
||||
-level: [1 | 2 | 3], 1 = model; 2 = models,controller; 3 = models,controllers,router
|
||||
-level: [1 | 2 | 3], 1 = models; 2 = models,controllers; 3 = models,controllers,router
|
||||
`,
|
||||
}
|
||||
|
||||
@ -102,19 +102,30 @@ func generateCode(cmd *Command, args []string) {
|
||||
case "docs":
|
||||
generateDocs(curpath)
|
||||
case "appcode":
|
||||
// load config
|
||||
err := loadConfig()
|
||||
if err != nil {
|
||||
ColorLog("[ERRO] Fail to parse bee.json[ %s ]\n", err)
|
||||
}
|
||||
cmd.Flag.Parse(args[1:])
|
||||
if driver == "" {
|
||||
driver = "mysql"
|
||||
driver = docValue(conf.Database.Driver)
|
||||
if driver == "" {
|
||||
driver = "mysql"
|
||||
}
|
||||
}
|
||||
if conn == "" {
|
||||
conn = "root:@tcp(127.0.0.1:3306)/test"
|
||||
conn = docValue(conf.Database.Conn)
|
||||
if conn == "" {
|
||||
conn = "root:@tcp(127.0.0.1:3306)/test"
|
||||
}
|
||||
}
|
||||
if level == "" {
|
||||
level = "1"
|
||||
level = "3"
|
||||
}
|
||||
ColorLog("[INFO] Using '%s' as 'driver'\n", driver)
|
||||
ColorLog("[INFO] Using '%s' as 'conn'\n", conn)
|
||||
ColorLog("[INFO] Using '%s' as 'tables'", tables)
|
||||
ColorLog("[INFO] Using '%s' as 'tables'\n", tables)
|
||||
ColorLog("[INFO] Using '%s' as 'level'\n", level)
|
||||
generateAppcode(string(driver), string(conn), string(level), string(tables), curpath)
|
||||
case "migration":
|
||||
|
15
migrate.go
15
migrate.go
@ -70,15 +70,26 @@ func runMigration(cmd *Command, args []string) {
|
||||
ColorLog("[HINT] Set $GOPATH in your environment vairables\n")
|
||||
os.Exit(2)
|
||||
}
|
||||
// load config
|
||||
err := loadConfig()
|
||||
if err != nil {
|
||||
ColorLog("[ERRO] Fail to parse bee.json[ %s ]\n", err)
|
||||
}
|
||||
// getting command line arguments
|
||||
if len(args) != 0 {
|
||||
cmd.Flag.Parse(args[1:])
|
||||
}
|
||||
if mDriver == "" {
|
||||
mDriver = "mysql"
|
||||
mDriver = docValue(conf.Database.Driver)
|
||||
if mDriver == "" {
|
||||
mDriver = "mysql"
|
||||
}
|
||||
}
|
||||
if mConn == "" {
|
||||
mConn = "root:@tcp(127.0.0.1:3306)/test"
|
||||
mConn = docValue(conf.Database.Conn)
|
||||
if mConn == "" {
|
||||
mConn = "root:@tcp(127.0.0.1:3306)/test"
|
||||
}
|
||||
}
|
||||
ColorLog("[INFO] Using '%s' as 'driver'\n", mDriver)
|
||||
ColorLog("[INFO] Using '%s' as 'conn'\n", mConn)
|
||||
|
Loading…
Reference in New Issue
Block a user