github.com/tilotech/tilores-cli@v0.28.0/cmd/version.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "runtime/debug" 6 7 "github.com/spf13/cobra" 8 ) 9 10 // versionCmd represents the version command 11 var versionCmd = &cobra.Command{ 12 Use: "version", 13 Short: "Print the version", 14 Long: "Print the version", 15 Run: func(_ *cobra.Command, _ []string) { 16 err := printVersion() 17 cobra.CheckErr(err) 18 }, 19 } 20 21 func init() { 22 rootCmd.AddCommand(versionCmd) 23 } 24 25 func printVersion() error { 26 buildInfo, ok := debug.ReadBuildInfo() 27 if !ok { 28 return fmt.Errorf("could not read BuildInfo") 29 } 30 fmt.Println(buildInfo.Main.Version) 31 return nil 32 }