github.com/masterhung0112/hk_server/v5@v5.0.0-20220302090640-ec71aef15e1c/cmd/hkserver/commands/version.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package commands 5 6 import ( 7 "github.com/spf13/cobra" 8 9 "github.com/masterhung0112/hk_server/v5/app" 10 "github.com/masterhung0112/hk_server/v5/model" 11 ) 12 13 var VersionCmd = &cobra.Command{ 14 Use: "version", 15 Short: "Display version information", 16 RunE: versionCmdF, 17 } 18 19 func init() { 20 VersionCmd.Flags().Bool("skip-server-start", false, "Skip the server initialization and return the Mattermost version without the DB version.") 21 22 RootCmd.AddCommand(VersionCmd) 23 } 24 25 func versionCmdF(command *cobra.Command, args []string) error { 26 skipStart, _ := command.Flags().GetBool("skip-server-start") 27 if skipStart { 28 printVersionNoDB() 29 return nil 30 } 31 32 a, err := InitDBCommandContextCobra(command) 33 if err != nil { 34 return err 35 } 36 defer a.Srv().Shutdown() 37 38 printVersion(a) 39 40 return nil 41 } 42 43 func printVersion(a *app.App) { 44 printVersionNoDB() 45 CommandPrintln("DB Version: " + a.Srv().Store.GetCurrentSchemaVersion()) 46 } 47 48 func printVersionNoDB() { 49 CommandPrintln("Version: " + model.CurrentVersion) 50 CommandPrintln("Build Number: " + model.BuildNumber) 51 CommandPrintln("Build Date: " + model.BuildDate) 52 CommandPrintln("Build Hash: " + model.BuildHash) 53 CommandPrintln("Build Enterprise Ready: " + model.BuildEnterpriseReady) 54 }