-
Notifications
You must be signed in to change notification settings - Fork 129
/
version.go
38 lines (31 loc) · 902 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
package cmd
import (
"fmt"
"os/exec"
"strings"
"github.com/spf13/cobra"
)
var versionString = "dev"
func init() {
rootCmd.AddCommand(versionCmd)
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of cf-terraforming",
Run: func(cmd *cobra.Command, args []string) {
if versionString == "dev" {
gitDescribe := exec.Command("git", "describe", "--tags", "--abbrev=0")
gitDescribeStdout, err := gitDescribe.Output()
if err != nil {
log.Error("failed to exec to `git`")
}
gitSha := exec.Command("git", "rev-parse", "--short=12", "HEAD")
gitShaStdout, err := gitSha.Output()
if err != nil {
log.Error("failed to exec to `git`")
}
versionString = strings.TrimSpace(string(gitDescribeStdout)) + "-" + versionString + "+" + strings.TrimSpace(string(gitShaStdout))
}
fmt.Printf("cf-terraforming %s\n", versionString)
},
}