/
version.go
41 lines (34 loc) · 890 Bytes
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package cmd
import (
"fmt"
"io"
"github.com/spf13/cobra"
)
type versionCmd struct {
out io.Writer
buildVersion string
buildCommit string
buildDate string
}
func newVersionCmd(buildVersion string, buildCommit string, buildDate string, out io.Writer) *cobra.Command {
version := &versionCmd{
out: out,
buildVersion: buildVersion,
buildCommit: buildCommit,
buildDate: buildDate,
}
// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of Ironman",
Long: `All software has versions. This is Ironman's.`,
RunE: func(cmd *cobra.Command, args []string) error {
return version.Run()
},
}
return versionCmd
}
func (v *versionCmd) Run() error {
fmt.Fprintf(v.out, "Ironman %s-%s Build date: %s\n", v.buildVersion, v.buildCommit, v.buildDate)
return nil
}