Skip to content

Commit a9e798f

Browse files
committed
修改版本打印
1 parent 165d4ef commit a9e798f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

server/base/cmd.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ func initCmd() {
6969
Run: func(cmd *cobra.Command, args []string) {
7070
// fmt.Println("cmd:", cmd.Use, args)
7171
runSrv = true
72+
73+
if rev {
74+
printVersion()
75+
os.Exit(0)
76+
}
7277
},
7378
}
7479

@@ -92,6 +97,7 @@ func initCmd() {
9297
// viper.SetDefault(v.Name, v.Value)
9398
}
9499

100+
rootCmd.Flags().BoolVarP(&rev, "version", "v", false, "display version info")
95101
rootCmd.AddCommand(initToolCmd())
96102

97103
cobra.OnInitialize(func() {
@@ -127,8 +133,7 @@ func initToolCmd() *cobra.Command {
127133
toolCmd.Run = func(cmd *cobra.Command, args []string) {
128134
switch {
129135
case rev:
130-
fmt.Printf("%s v%s build on %s [%s, %s] commit_id(%s) \n",
131-
APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, CommitId)
136+
printVersion()
132137
case secret:
133138
s, _ := utils.RandSecret(40, 60)
134139
s = strings.Trim(s, "=")
@@ -145,3 +150,8 @@ func initToolCmd() *cobra.Command {
145150

146151
return toolCmd
147152
}
153+
154+
func printVersion() {
155+
fmt.Printf("%s v%s build on %s [%s, %s] commit_id(%s) \n",
156+
APP_NAME, APP_VER, runtime.Version(), runtime.GOOS, runtime.GOARCH, CommitId)
157+
}

0 commit comments

Comments
 (0)