1
1
package main
2
2
3
3
import (
4
+ "debug/buildinfo"
4
5
"flag"
5
6
"fmt"
6
7
"log"
23
24
skipTables string
24
25
IgnoreCharset bool
25
26
config * conf.Conf
27
+ PrintVersion bool
28
+ Version string
29
+ BuildTime string
26
30
)
27
31
28
32
func init () {
@@ -36,9 +40,15 @@ func init() {
36
40
fs .StringVar (& MysqlVersion , "mysql-version" , "" , "mysql版本,仅使用文件比对时需要指定,默认值为:" + vtconfig .DefaultMySQLVersion )
37
41
fs .StringVar (& skipTables , "skip-tables" , "" , "跳过特定表比对,多个表使用逗号分隔" )
38
42
fs .BoolVar (& IgnoreCharset , "ignore-charset" , false , "忽略字符集比对" )
43
+ fs .BoolVar (& PrintVersion , "version" , false , "打印版本信息" )
39
44
40
45
fs .Parse (os .Args [1 :])
41
46
47
+ if PrintVersion {
48
+ printVersion ()
49
+ os .Exit (0 )
50
+ }
51
+
42
52
var err error
43
53
44
54
config , err = conf .NewConfFromFile (confFileName )
@@ -130,3 +140,34 @@ func main() {
130
140
log .Printf ("diff结果SQL文件生成成功[%s]" , config .SaveSqlPath )
131
141
}
132
142
}
143
+
144
+ func printVersion () {
145
+ if Version == "" {
146
+ Version = "dev"
147
+ }
148
+ fmt .Printf ("version: \t %s\n " , Version )
149
+ if BuildTime == "" {
150
+ BuildTime = "unknown"
151
+ }
152
+ fmt .Printf ("构建时间: \t %s\n " , BuildTime )
153
+
154
+ selfFile := os .Args [0 ]
155
+ res , err := buildinfo .ReadFile (selfFile )
156
+ if err != nil {
157
+ os .Exit (0 )
158
+ }
159
+
160
+ fmt .Printf ("Go版本: \t %s\n " , res .GoVersion )
161
+
162
+ for _ , item := range res .Settings {
163
+ if item .Key == "vcs.revision" {
164
+ fmt .Printf ("commit id: \t %s\n " , item .Value )
165
+ }
166
+ if item .Key == "vcs.time" {
167
+ fmt .Printf ("commit time: \t %s\n " , item .Value )
168
+ }
169
+ if item .Key == "vcs.modified" {
170
+ fmt .Printf ("dirty: \t \t %s\n " , item .Value )
171
+ }
172
+ }
173
+ }
0 commit comments