github.com/jaypipes/ghw@v0.21.1/cmd/ghwc/commands/version.go (about) 1 // 2 // Use and distribution licensed under the Apache license version 2. 3 // 4 // See the COPYING file in the root project directory for full text. 5 // 6 7 package commands 8 9 import ( 10 "fmt" 11 "runtime" 12 13 "github.com/spf13/cobra" 14 ) 15 16 const debugHeader = ` 17 Date: %s 18 Build: %s 19 Version: %s 20 Git Hash: %s 21 ` 22 23 // versionCmd represents the version command 24 var versionCmd = &cobra.Command{ 25 Use: "version", 26 Short: "Display the version of gofile", 27 Run: func(cmd *cobra.Command, args []string) { 28 goVersion := fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH) 29 fmt.Printf(debugHeader, buildDate, goVersion, version, buildHash) 30 }, 31 } 32 33 func init() { 34 rootCmd.AddCommand(versionCmd) 35 }