From 07bcce359a13a00a1596a27ec596a9852fab1339 Mon Sep 17 00:00:00 2001 From: ZhengYang Date: Wed, 13 Aug 2014 14:13:07 +0800 Subject: [PATCH 1/4] generate everything by default --- g.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/g.go b/g.go index c1dc8df..5117f4a 100644 --- a/g.go +++ b/g.go @@ -110,7 +110,7 @@ func generateCode(cmd *Command, args []string) { 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) From 4775fc3e819c0f4521a490bd0990ca116cc9fa0b Mon Sep 17 00:00:00 2001 From: ZhengYang Date: Wed, 13 Aug 2014 14:14:11 +0800 Subject: [PATCH 2/4] corrections on help message --- g.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/g.go b/g.go index 5117f4a..61bae82 100644 --- a/g.go +++ b/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 `, } From 64f3acca2641f53e4c031b62cbc3bbf73ea0da73 Mon Sep 17 00:00:00 2001 From: ZhengYang Date: Wed, 13 Aug 2014 14:34:12 +0800 Subject: [PATCH 3/4] loading driver and connStr from json if there is no commandline options specified --- bee.json | 6 +++++- conf.go | 10 +++++++++- migrate.go | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/bee.json b/bee.json index 0c0ee71..41dced8 100644 --- a/bee.json +++ b/bee.json @@ -13,5 +13,9 @@ "others": [] }, "cmd_args": [], - "envs": [] + "envs": [], + "database": { + "driver": "mysql", + "conn": "root:@tcp(127.0.0.1:3306)/test" + } } \ No newline at end of file diff --git a/conf.go b/conf.go index 0561c0d..5a116b5 100644 --- a/conf.go +++ b/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. diff --git a/migrate.go b/migrate.go index a644aad..610d895 100644 --- a/migrate.go +++ b/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) From e455509adbce1b6c089e56c244d3c05a9f64b2d8 Mon Sep 17 00:00:00 2001 From: ZhengYang Date: Wed, 13 Aug 2014 14:48:20 +0800 Subject: [PATCH 4/4] load params from json and minor output format fix --- g.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/g.go b/g.go index 61bae82..2ca735d 100644 --- a/g.go +++ b/g.go @@ -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 = "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":