From 1c538418f7304da8b57ea5891b0e93e09b2c81d7 Mon Sep 17 00:00:00 2001 From: Johannes Brunswicker Date: Thu, 11 Apr 2024 13:06:08 +0200 Subject: [PATCH 1/3] - version variable must not be initialized to be set during the build process. See https://stackoverflow.com/questions/11354518/application-auto-build-versioning --- main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 0697f9d0..35070913 100644 --- a/main.go +++ b/main.go @@ -47,7 +47,7 @@ const ( ) var logger = lib.InitLogger() -var version = "0.12.0" +var version *string func main() { dir := lib.GetCurrentDirectory() @@ -89,7 +89,11 @@ func main() { switch { case *versionFlag: //if *versionFlag { - logger.Infof("Version: %s", version) + if version != nil { + logger.Infof("Version: %s", version) + } else { + logger.Error("Version not set correctly.") + } case *helpFlag: //} else if *helpFlag { usageMessage() From c0b581eb866ca37faa1005523fe3501c171868fc Mon Sep 17 00:00:00 2001 From: Johannes Brunswicker Date: Thu, 11 Apr 2024 14:05:46 +0200 Subject: [PATCH 2/3] Update main.go Co-authored-by: George L. Yermulnik --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 35070913..0ad68e5c 100644 --- a/main.go +++ b/main.go @@ -90,9 +90,9 @@ func main() { case *versionFlag: //if *versionFlag { if version != nil { - logger.Infof("Version: %s", version) + fmt.Printf("Version: %s\n", version) } else { - logger.Error("Version not set correctly.") + fmt.Println("Version not defined during build.") } case *helpFlag: //} else if *helpFlag { From c8e8c04a3310187ab0dd2619b4682b7d657d3d7e Mon Sep 17 00:00:00 2001 From: Johannes Brunswicker Date: Thu, 11 Apr 2024 14:19:27 +0200 Subject: [PATCH 3/3] - fix error with *string type --- main.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 0ad68e5c..c9d75edf 100644 --- a/main.go +++ b/main.go @@ -47,7 +47,7 @@ const ( ) var logger = lib.InitLogger() -var version *string +var version string func main() { dir := lib.GetCurrentDirectory() @@ -79,7 +79,6 @@ func main() { logger.Fatalf("Unable to get home directory: %v", err) os.Exit(1) } - TFVersionFile := filepath.Join(*chDirPath, tfvFilename) //settings for .terraform-version file in current directory (tfenv compatible) RCFile := filepath.Join(*chDirPath, rcFilename) //settings for .tfswitchrc file in current directory (backward compatible purpose) TOMLConfigFile := filepath.Join(*chDirPath, tomlFilename) //settings for .tfswitch.toml file in current directory (option to specify bin directory) @@ -89,7 +88,7 @@ func main() { switch { case *versionFlag: //if *versionFlag { - if version != nil { + if version != "" { fmt.Printf("Version: %s\n", version) } else { fmt.Println("Version not defined during build.")