diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..77f0f48 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,32 @@ +package cmd + +import ( + "fmt" + "runtime" + + "github.com/mathismqn/godeez/internal/buildinfo" + "github.com/spf13/cobra" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the current version of GoDeez", + Args: cobra.NoArgs, + Run: func(cmd *cobra.Command, args []string) { + fmt.Printf("godeez %s\n", buildinfo.Version()) + + if commit := buildinfo.Commit(); commit != "" { + fmt.Printf(" commit: %s\n", commit) + } + if date := buildinfo.Date(); date != "" { + fmt.Printf(" built: %s\n", date) + } + + fmt.Printf(" go: %s\n", runtime.Version()) + fmt.Printf(" platform: %s/%s\n", runtime.GOOS, runtime.GOARCH) + }, +} + +func init() { + RootCmd.AddCommand(versionCmd) +}