refactor: build cobra commands with constructors

This commit is contained in:
Mathis Maquenne
2026-08-05 11:35:52 +02:00
parent 0ab25addd5
commit 3c9da5f24a
6 changed files with 121 additions and 111 deletions
+17 -19
View File
@@ -8,25 +8,23 @@ import (
"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())
func newVersionCmd() *cobra.Command {
return &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)
}
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)
fmt.Printf(" go: %s\n", runtime.Version())
fmt.Printf(" platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
},
}
}