Skip to content

Commit c510ee8

Browse files
author
cg33
committed
update cli
1 parent 630874f commit c510ee8

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ vendor/**
1212
!vendor/vendor.json
1313
logs
1414
go.sum
15-
modules/db/go.sum
15+
modules/db/go.sum
16+
admincli/build

admincli/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
GOCMD=go
2+
GOBUILD=$(GOCMD) build
3+
BINARY_NAME=admincli
4+
VERSION=v0.2.4
5+
6+
all:
7+
GO111MODULE=on $(GOBUILD) -o ./build/mac/$(BINARY_NAME)
8+
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o ./build/linux/x86_64/$(BINARY_NAME)
9+
GO111MODULE=on CGO_ENABLED=0 GOOS=linux GOARCH=arm $(GOBUILD) -o ./build/linux/armel/$(BINARY_NAME)
10+
GO111MODULE=on CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o ./build/windows/x86_64/$(BINARY_NAME).exe
11+
GO111MODULE=on CGO_ENABLED=0 GOOS=windows GOARCH=386 $(GOBUILD) -o ./build/windows/i386/$(BINARY_NAME).exe
12+
zip -q build/linux/armel/admincli_linux_armel_$(VERSION).zip build/linux/armel/admincli
13+
zip -q build/linux/x86_64/admincli_linux_x86_64_$(VERSION).zip build/linux/x86_64/admincli
14+
zip -q build/windows/x86_64/admincli_windows_x86_64_$(VERSION).zip build/windows/x86_64/admincli.exe
15+
zip -q build/windows/i386/admincli_windows_i386_$(VERSION).zip build/windows/i386/admincli.exe
16+
zip -q build/mac/admincli_darwin_x86_64_$(VERSION).zip build/mac/admincli

admincli/cli.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package main
77
import (
88
"fmt"
99
"github.com/AlecAivazis/survey/v2"
10+
"github.com/AlecAivazis/survey/v2/core"
1011
"github.com/chenhg5/go-admin/modules/config"
1112
"github.com/chenhg5/go-admin/modules/db"
1213
"github.com/chenhg5/go-admin/modules/system"
@@ -113,15 +114,15 @@ func generating() {
113114

114115
err := survey.Ask(qs, &result)
115116
checkError(err)
116-
driver := result["driver"].(string)
117+
driver := result["driver"].(core.OptionAnswer)
117118

118119
var (
119120
cfg map[string]config.Database
120121
name string
121-
conn = db.GetConnectionByDriver(driver)
122+
conn = db.GetConnectionByDriver(driver.Value)
122123
)
123124

124-
if driver != "sqlite" {
125+
if driver.Value != "sqlite" {
125126
host := promptWithDefault("sql address", "127.0.0.1")
126127
port := promptWithDefault("sql port", "3306")
127128
user := promptWithDefault("sql username", "root")
@@ -142,7 +143,7 @@ func generating() {
142143
Name: name,
143144
MaxIdleCon: 50,
144145
MaxOpenCon: 150,
145-
Driver: driver,
146+
Driver: driver.Value,
146147
File: "",
147148
},
148149
}
@@ -157,7 +158,7 @@ func generating() {
157158
}
158159
cfg = map[string]config.Database{
159160
"default": {
160-
Driver: driver,
161+
Driver: driver.Value,
161162
File: file,
162163
},
163164
}
@@ -169,7 +170,7 @@ func generating() {
169170
// step 2. show tables
170171
tableModels, _ := db.WithDriver(conn.GetName()).ShowTables()
171172

172-
tables := getTablesFromSqlResult(tableModels, driver, name)
173+
tables := getTablesFromSqlResult(tableModels, driver.Value, name)
173174
if len(tables) == 0 {
174175
exitWithError(`no tables, you should build a table of your own business first.
175176
@@ -191,7 +192,7 @@ see: http://www.go-admin.cn/en/docs/#/plugins/admin`)
191192

192193
fieldField := "Field"
193194
typeField := "Type"
194-
if driver == "postgresql" {
195+
if driver.Value == "postgresql" {
195196
fieldField = "column_name"
196197
typeField = "udt_name"
197198
}
@@ -200,7 +201,7 @@ see: http://www.go-admin.cn/en/docs/#/plugins/admin`)
200201
for i := 0; i < len(chooseTables); i++ {
201202
_ = bar.Add(1)
202203
time.Sleep(10 * time.Millisecond)
203-
generateFile(chooseTables[i], conn, fieldField, typeField, packageName, driver, outputPath)
204+
generateFile(chooseTables[i], conn, fieldField, typeField, packageName, driver.Value, outputPath)
204205
}
205206
generateTables(outputPath, chooseTables, packageName)
206207

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ go 1.12
55
require (
66
cloud.google.com/go v0.37.4 // indirect
77
github.com/360EntSecGroup-Skylar/excelize v1.4.1 // indirect
8-
github.com/AlecAivazis/survey/v2 v2.0.4 // indirect
8+
github.com/AlecAivazis/survey/v2 v2.0.4
99
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e
1010
github.com/Netflix/go-expect v0.0.0-20180928190340-9d1f4485533b // indirect
1111
github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f
12-
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
12+
github.com/go-bindata/go-bindata v3.1.2+incompatible
1313
github.com/go-sql-driver/mysql v1.4.1
1414
github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c // indirect
15-
github.com/jawher/mow.cli v1.1.0 // indirect
15+
github.com/jawher/mow.cli v1.1.0
1616
github.com/juju/loggo v0.0.0-20190212223446-d976af380377 // indirect
1717
github.com/juju/testing v0.0.0-20190418112600-6570bd8f8541 // indirect
1818
github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
@@ -22,7 +22,7 @@ require (
2222
github.com/lib/pq v1.2.0
2323
github.com/mattn/go-sqlite3 v1.11.0
2424
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b
25-
github.com/schollz/progressbar v1.0.0 // indirect
25+
github.com/schollz/progressbar v1.0.0
2626
github.com/schollz/progressbar/v2 v2.13.0 // indirect
2727
github.com/sirupsen/logrus v1.4.2
2828
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect

modules/system/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package system
22

3-
const Version = "v0.2.3"
3+
const Version = "v0.2.4"

0 commit comments

Comments
 (0)