github.com/ianfoo/lab@v0.9.5-0.20180123060006-5ed79f2ccfc7/cmd/version.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 6 "github.com/spf13/cobra" 7 "github.com/zaquestion/lab/internal/git" 8 ) 9 10 // Version is set by main during build 11 var Version string 12 13 // versionCmd represents the version command 14 var versionCmd = &cobra.Command{ 15 Use: "version", 16 Short: "", 17 Long: ``, 18 Run: func(cmd *cobra.Command, args []string) { 19 git := git.New("version") 20 git.Stdout = nil 21 git.Stderr = nil 22 version, _ := git.Output() 23 fmt.Printf("%s%s %s\n", string(version), "lab version", Version) 24 }, 25 } 26 27 func init() { 28 RootCmd.AddCommand(versionCmd) 29 }