package cmd import ( "fmt" "runtime/debug" "github.com/spf13/cobra" ) var versionCmd = &cobra.Command{ Use: "version", Short: "print the program version", Run: func(cmd *cobra.Command, args []string) { if info, ok := debug.ReadBuildInfo(); ok { fmt.Println(info.Main.Version) } else { fmt.Println("(devel)") } }, } func init() { rootCmd.AddCommand(versionCmd) }