code.cestus.io/tools/fabricator@v0.4.3/pkg/cmd/version/version.go (about) 1 package version 2 3 import ( 4 "fmt" 5 6 "code.cestus.io/libs/buildinfo" 7 "code.cestus.io/tools/fabricator/internal/pkg/util" 8 "code.cestus.io/tools/fabricator/pkg/fabricator" 9 "github.com/spf13/cobra" 10 ) 11 12 type options struct { 13 fabricator.IOStreams 14 } 15 16 // NewOptions returns initialized Options 17 func NewOptions(ioStreams fabricator.IOStreams) *options { 18 return &options{ 19 IOStreams: ioStreams, 20 } 21 } 22 23 // Run executes version command 24 func (o *options) Run() error { 25 version := buildinfo.ProvideBuildInfo() 26 fmt.Fprintf(o.Out, "Name: %s\n", version.Name) 27 fmt.Fprintf(o.Out, "Version: %s\n", version.Version) 28 fmt.Fprintf(o.Out, "BuildDate: %s\n", version.BuildDate) 29 fmt.Fprintf(o.Out, "Go-Version: %s\n", version.GoVersion) 30 fmt.Fprintf(o.Out, "Platform: %s\n", version.Platform) 31 fmt.Fprintf(o.Out, "OS: %s\n", version.OS) 32 return nil 33 } 34 35 func NewCmdVersion(ioStreams fabricator.IOStreams) *cobra.Command { 36 o := NewOptions(ioStreams) 37 cmd := &cobra.Command{ 38 Use: "version", 39 Short: "Print the version", 40 Long: "Print the version", 41 Example: "", 42 Run: func(cmd *cobra.Command, args []string) { 43 util.CheckErr(o.Run()) 44 }, 45 } 46 return cmd 47 }