...
1
21
22 package cmdx
23
24 import (
25 "fmt"
26 "os"
27
28 "github.com/spf13/cobra"
29 )
30
31
32 func Version(gitTag, gitHash, buildTime *string) *cobra.Command {
33 return &cobra.Command{
34 Use: "version",
35 Short: "Show the build version, build time, and git hash",
36 Run: func(cmd *cobra.Command, args []string) {
37 if len(*gitTag) == 0 {
38 fmt.Fprintln(os.Stderr, "Unable to determine version because the build process did not properly configure it.")
39 } else {
40 fmt.Printf("Version: %s\n", *gitTag)
41 }
42
43 if len(*gitHash) == 0 {
44 fmt.Fprintln(os.Stderr, "Unable to determine build commit because the build process did not properly configure it.")
45 } else {
46 fmt.Printf("Build Commit: %s\n", *gitHash)
47 }
48
49 if len(*buildTime) == 0 {
50 fmt.Fprintln(os.Stderr, "Unable to determine build timestamp because the build process did not properly configure it.")
51 } else {
52 fmt.Printf("Build Timestamp: %s\n", *buildTime)
53 }
54 },
55 }
56 }
57
View as plain text