From 01cfb2c3d138131799ad1bff6b159171350edee2 Mon Sep 17 00:00:00 2001 From: Tristan Morgan Date: Thu, 2 May 2024 11:19:49 +1000 Subject: [PATCH] Allow build flags to set version '-X main.Version=0.0.4 -X main.VersionPrerelease= ' --- cmd/bfg/main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/bfg/main.go b/cmd/bfg/main.go index 1b1b37f..cd05c4f 100644 --- a/cmd/bfg/main.go +++ b/cmd/bfg/main.go @@ -11,6 +11,16 @@ import ( "github.com/tristanmorgan/bfg/parser" ) +var ( + // Version is the main version number that is being run at the moment. + Version = "0.0.1" + + // VersionPrerelease is A pre-release marker for the Version. If this is "" + // (empty string) then it means that it is a final release. Otherwise, this + // is a pre-release such as "-dev" (in development), -"beta", "-rc1", etc. + VersionPrerelease = "-dev" +) + func main() { version := flag.Bool("version", false, "display version") eight := flag.Bool("eight", false, "eight bit execution") @@ -24,7 +34,7 @@ func main() { flag.Parse() if *version { - fmt.Println("Version 0.0.1") + fmt.Printf("Version: v%s%s\n", Version, VersionPrerelease) os.Exit(0) }