github.com/tommi2day/pwcli@v0.0.0-20240317203041-4d1177a5ab91/cmd/version.go (about) 1 // Package cmd commands 2 package cmd 3 4 import ( 5 "fmt" 6 7 log "github.com/sirupsen/logrus" 8 "github.com/spf13/cobra" 9 ) 10 11 var ( 12 versionCmd = &cobra.Command{ 13 Use: "version", 14 Short: "version print version string", 15 Long: ``, 16 Run: func(_ *cobra.Command, _ []string) { 17 v := GetVersion(true) 18 log.Debugf("Version: %s", v) 19 }, 20 } 21 ) 22 23 // Version, Build Commit and Date are filled in during build by the Makefile 24 // noinspection GoUnusedGlobalVariable 25 var ( 26 Name = configName 27 Version = "- not set -" 28 Commit = "snapshot" 29 Date = "" 30 ) 31 32 func init() { 33 RootCmd.AddCommand(versionCmd) 34 } 35 36 // GetVersion extract compiled version info 37 func GetVersion(print bool) (txt string) { 38 name := Name 39 commit := Commit 40 version := Version 41 date := Date 42 txt = fmt.Sprintf("%s version %s (%s - %s)", name, version, commit, date) 43 if print { 44 fmt.Println(txt) 45 } 46 return 47 }