From 4d98872da51f0d6194df7ac70fe0a6395edb64aa Mon Sep 17 00:00:00 2001 From: Evan Hearne Date: Wed, 22 May 2024 12:54:25 +0100 Subject: [PATCH] added code to display version as commit hash --- version/version.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/version/version.go b/version/version.go index ed1f230..2e51c77 100644 --- a/version/version.go +++ b/version/version.go @@ -15,6 +15,23 @@ limitations under the License. */ package version +import ( + "fmt" + "os/exec" + "strings" +) + +func getCommitHash() string { + cmd := exec.Command("git", "rev-parse", "HEAD") + output, err := cmd.Output() + if err != nil { + fmt.Println("Error occurred while trying to retrieve the version of kuadrantctl. Do you have Git installed?") + return "v0.0.0" + } + commitHash := strings.TrimSpace(string(output))[:7] + return commitHash +} + var ( - Version = "v0.0.0" + Version = "dev - " + getCommitHash() )