From 96bb53a8b7e4c259aa148abcd72096b89044583c Mon Sep 17 00:00:00 2001 From: "warren.veerasingam" Date: Thu, 4 Feb 2021 00:24:50 +0800 Subject: [PATCH] added env variable option --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index 8e62439d..07011ab3 100644 --- a/main.go +++ b/main.go @@ -129,6 +129,8 @@ func main() { installVersion(tfversion, &binPath) case checkTFModuleFileExist(dir) && len(args) == 0: installTFProvidedModule(dir, &binPath) + case checkEnvExist() && len(args) == 0 && version == "": + installVersion(os.Getenv("TFVERSION"), custBinPath) case version != "": installVersion(version, &binPath) default: @@ -174,6 +176,10 @@ func main() { case checkTFModuleFileExist(dir) && len(args) == 0: installTFProvidedModule(dir, custBinPath) + /* if TF environment variable is set */ + case checkEnvExist() && len(args) == 0: + installVersion(os.Getenv("TFVERSION"), custBinPath) + // if no arg is provided default: listAll := false //set list all false - only official release will be displayed @@ -273,6 +279,16 @@ func checkTFModuleFileExist(dir string) bool { return false } +// fileExists checks if a file exists and is not a directory before we +// try using it to prevent further errors. +func checkEnvExist() bool { + tfversion := os.Getenv("TFVERSION") + if tfversion != "" { + return true + } + return false +} + /* parses everything in the toml file, return required version and bin path */ func getParamsTOML(binPath string, dir string) (string, string) { path, _ := homedir.Dir()