Skip to content

Commit 8195d14

Browse files
committed
修正文件conf读取参数错误
1 parent fcba8e5 commit 8195d14

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,33 @@ go get github.com/xfali/gobatis-cmd/cmd/gobatis-cmd
99
```
1010

1111
## 使用
12+
13+
```
14+
gobatis-cmd -f configs/gobatis-conf.json
15+
```
16+
```
17+
{
18+
"driver": "mysql",
19+
"path": ".",
20+
"package": "test",
21+
"namespace": "test",
22+
"modelFile": "test_model.go",
23+
"tagName": "xfield",
24+
"mapperFile": "xml",
25+
"plugin": "",
26+
"keyword": false,
27+
"tableName": "",
28+
"dbName": "test_db",
29+
"host": "localhost",
30+
"port": 3306,
31+
"user": "",
32+
"password": ""
33+
}
34+
```
35+
或者使用命令参数:
1236
```
1337
gobatis-cmd -driver=mysql -host=localhost -port=3306 -user=test -pw=test -db=testdb -pkg=test_package -mapper=xml -namespace=test -path=.
1438
```
15-
1639
```
1740
-db string
1841
指定解析的数据库名称

cmd/gobatis-cmd/main.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ package main
1111
import (
1212
"encoding/json"
1313
"flag"
14+
"fmt"
1415
"github.com/xfali/gobatis-cmd/internal/pkg/db"
1516
"github.com/xfali/gobatis-cmd/internal/pkg/generator"
1617
"github.com/xfali/gobatis-cmd/pkg/config"
@@ -50,27 +51,28 @@ func main() {
5051
if *confFile != "" {
5152
err := loadFromFile(&conf, *confFile)
5253
if err != nil {
54+
fmt.Println(err)
5355
os.Exit(1)
5456
}
57+
conf.Path = formatPath(conf.Path)
58+
} else {
59+
conf.Driver = *driver
60+
conf.Path = formatPath(*path)
61+
conf.PackageName = *packageName
62+
conf.Namespace = *namespace
63+
conf.ModelFile = *modelfile
64+
conf.TagName = *tagName
65+
conf.MapperFile = *mapper
66+
conf.Plugin = *plugin
67+
conf.Keyword = *keyword
68+
conf.TableName = *tableName
69+
conf.DBName = *dbName
70+
conf.Host = *host
71+
conf.Port = *port
72+
conf.User = *username
73+
conf.Password = *pw
5574
}
5675

57-
root := formatPath(*path)
58-
conf.Driver = *driver
59-
conf.Path = root
60-
conf.PackageName = *packageName
61-
conf.Namespace = *namespace
62-
conf.ModelFile = *modelfile
63-
conf.TagName = *tagName
64-
conf.MapperFile = *mapper
65-
conf.Plugin = *plugin
66-
conf.Keyword = *keyword
67-
conf.TableName = *tableName
68-
conf.DBName = *dbName
69-
conf.Host = *host
70-
conf.Port = *port
71-
conf.User = *username
72-
conf.Password = *pw
73-
7476
err := dbDriver.Open(conf.Driver, db.GenDBInfo(conf.Driver, conf.DBName, conf.User, conf.Password, conf.Host, conf.Port))
7577
if err != nil {
7678
log.Print(err)
@@ -98,6 +100,7 @@ func loadFromFile(conf *config.FileConfig, path string) error {
98100
if err != nil {
99101
return err
100102
}
103+
fmt.Printf("config file: %s\n", string(b))
101104
return json.Unmarshal(b, conf)
102105
}
103106

0 commit comments

Comments
 (0)