From b5ca32e147b8c7abf92080cd933535cf0964177e Mon Sep 17 00:00:00 2001 From: "warren.veerasingam" Date: Wed, 15 Jun 2022 15:05:37 -0500 Subject: [PATCH 1/4] Fix documentation and added show stable for toml file users --- main.go | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 4951b54c..e1035049 100644 --- a/main.go +++ b/main.go @@ -54,10 +54,10 @@ func main() { dir := lib.GetCurrentDirectory() custBinPath := getopt.StringLong("bin", 'b', lib.ConvertExecutableExt(defaultBin), "Custom binary path. Ex: tfswitch -b "+lib.ConvertExecutableExt("/Users/username/bin/terraform")) listAllFlag := getopt.BoolLong("list-all", 'l', "List all versions of terraform - including beta and rc") - latestPre := getopt.StringLong("latest-pre", 'p', defaultLatest, "Latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest)") - showLatestPre := getopt.StringLong("show-latest-pre", 'P', defaultLatest, "Show latest pre-release implicit version. Ex: tfswitch --show-latest-pre 0.13 prints 0.13.0-rc1 (latest)") - latestStable := getopt.StringLong("latest-stable", 's', defaultLatest, "Latest implicit version. Ex: tfswitch --latest-stable 0.13 downloads 0.13.7 (latest)") - showLatestStable := getopt.StringLong("show-latest-stable", 'S', defaultLatest, "Show latest implicit version. Ex: tfswitch --show-latest-stable 0.13 prints 0.13.7 (latest)") + latestPre := getopt.StringLong("latest-pre", 'p', defaultLatest, "Latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1") + showLatestPre := getopt.StringLong("show-latest-pre", 'P', defaultLatest, "Show latest pre-release implicit version. Ex: tfswitch --show-latest-pre 0.13 prints 0.13.0-rc1") + latestStable := getopt.StringLong("latest-stable", 's', defaultLatest, "Latest implicit version. Ex: tfswitch --latest-stable 1.0.0 downloads <1.1.0, >=1.0.0, 1.0 downloads <2.0.0, >=1.0.0") + showLatestStable := getopt.StringLong("show-latest-stable", 'S', defaultLatest, "Show latest implicit version. Ex: tfswitch --show-latest-stable 0.13 prints 0.15.5") latestFlag := getopt.BoolLong("latest", 'u', "Get latest stable version") showLatestFlag := getopt.BoolLong("show-latest", 'U', "Show latest stable version") mirrorURL := getopt.StringLong("mirror", 'm', defaultMirror, "Install from a remote API other than the default. Default: "+defaultMirror) @@ -106,17 +106,25 @@ func main() { case *listAllFlag: listAll := true //set list all true - all versions including beta and rc will be displayed installOption(listAll, &binPath, mirrorURL) - /* latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest) */ + /* latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 */ case *latestPre != "": preRelease := true - installLatestImplicitVersion(*latestPre, custBinPath, mirrorURL, preRelease) - /* latest implicit version. Ex: tfswitch --latest 0.13 downloads 0.13.5 (latest) */ + installLatestImplicitVersion(*latestPre, &binPath, mirrorURL, preRelease) + /* show latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 */ + case *showLatestPre != "": + preRelease := true + showLatestImplicitVersion(*showLatestPre, &binPath, mirrorURL, preRelease) + /* latest implicit version. Ex: tfswitch --latest-stable 1.0.0 downloads <1.1.0, >=1.0.0, 1.0 downloads <2.0.0, >=1.0.0" */ case *latestStable != "": preRelease := false - installLatestImplicitVersion(*latestStable, custBinPath, mirrorURL, preRelease) + installLatestImplicitVersion(*latestStable, &binPath, mirrorURL, preRelease) + /* show latest implicit stable version. Ex: tfswitch --latest 0.13 prints 0.15.5 */ + case *showLatestStable != "": + preRelease := false + showLatestImplicitVersion(*showLatestStable, &binPath, mirrorURL, preRelease) /* latest stable version */ case *latestFlag: - installLatestVersion(custBinPath, mirrorURL) + installLatestVersion(&binPath, mirrorURL) /* version provided on command line as arg */ case len(args) == 1: installVersion(args[0], &binPath, mirrorURL) @@ -137,7 +145,7 @@ func main() { case checkTFEnvExist() && len(args) == 0 && version == "": tfversion := os.Getenv("TF_VERSION") fmt.Printf("Terraform version environment variable: %s\n", tfversion) - installVersion(tfversion, custBinPath, mirrorURL) + installVersion(tfversion, &binPath, mirrorURL) /* if terragrunt.hcl file found (IN ADDITION TO A TOML FILE) */ case fileExists(TGHACLFile) && checkVersionDefinedHCL(&TGHACLFile) && len(args) == 0: installTGHclFile(&TGHACLFile, &binPath, mirrorURL) @@ -153,22 +161,22 @@ func main() { case *listAllFlag: installWithListAll(custBinPath, mirrorURL) - /* latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest) */ + /* latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 */ case *latestPre != "": preRelease := true installLatestImplicitVersion(*latestPre, custBinPath, mirrorURL, preRelease) - /* show latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest) */ + /* show latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 */ case *showLatestPre != "": preRelease := true showLatestImplicitVersion(*showLatestPre, custBinPath, mirrorURL, preRelease) - /* latest implicit version. Ex: tfswitch --latest 0.13 downloads 0.13.5 (latest) */ + /* latest implicit version. Ex: tfswitch --latest-stable 1.0.0 downloads <1.1.0, >=1.0.0, 1.0 downloads <2.0.0, >=1.0.0 */ case *latestStable != "": preRelease := false installLatestImplicitVersion(*latestStable, custBinPath, mirrorURL, preRelease) - /* show latest implicit stable version. Ex: tfswitch --latest 0.13 downloads 0.13.5 (latest) */ + /* show latest implicit stable version. Ex: tfswitch --latest 0.13 prints 0.15.5 */ case *showLatestStable != "": preRelease := false showLatestImplicitVersion(*showLatestStable, custBinPath, mirrorURL, preRelease) From 40fa8f7614b74b294bc95936c1131791eca7ea66 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam" Date: Sun, 19 Jun 2022 22:35:47 -0500 Subject: [PATCH 2/4] Update readme and quick start --- www/docs/Quick-Start.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/www/docs/Quick-Start.md b/www/docs/Quick-Start.md index fa689361..4e31d639 100644 --- a/www/docs/Quick-Start.md +++ b/www/docs/Quick-Start.md @@ -35,24 +35,24 @@ tfswitch #will automatically switch to terraform version 0.14.4 3. Hit **Enter** to install. ### Install latest implicit version for stable releases 1. Install the latest implicit stable version. -2. Ex: `tfswitch -s 0.13` or `tfswitch --latest-stable 0.13` downloads 0.13.6 (latest) version. +2. Ex: `tfswitch -s 0.13` or `tfswitch --latest-stable 0.13` downloads <1.1.0, >=1.0.0, 1.0 downloads <2.0.0, >=1.0.0. 3. Hit **Enter** to install. ### Install latest implicit version for beta, alpha and release candidates(rc) 1. Install the latest implicit pre-release version. -2. Ex: `tfswitch -p 0.13` or `tfswitch --latest-pre 0.13` downloads 0.13.0-rc1 (latest) version. +2. Ex: `tfswitch -p 0.13` or `tfswitch --latest-pre 0.13` downloads 0.13.0-rc1. 3. Hit **Enter** to install. ### Show latest version only 1. Just show what the latest version is. 2. Run `tfswitch -U` or `tfswitch --show-latest` -3. Hit **Enter** to show. +3. Hit **Enter** to print. ### Show latest implicit version for stable releases 1. Show the latest implicit stable version. -2. Ex: `tfswitch -S 0.13` or `tfswitch --show-latest-stable 0.13` shows 0.13.6 (latest) version. -3. Hit **Enter** to show. +2. Ex: `tfswitch -S 0.13` or `tfswitch --show-latest-stable 0.13` prints 0.15.5. +3. Hit **Enter** to print. ### Show latest implicit version for beta, alpha and release candidates(rc) 1. Show the latest implicit pre-release version. -2. Ex: `tfswitch -P 0.13` or `tfswitch --show-latest-pre 0.13` shows 0.13.0-rc1 (latest) version. -3. Hit **Enter** to show. +2. Ex: `tfswitch -P 0.13` or `tfswitch --show-latest-pre 0.13` prints 0.13.0-rc1. +3. Hit **Enter** to print. ### Use version.tf file If a .tf file with the terraform constrain is included in the current directory, it should automatically download or switch to that terraform version. For example, the following should automatically switch terraform to the lastest version: ``` From b3f55b82e482b7f2b1bc5e2c257b0c3eb93068ed Mon Sep 17 00:00:00 2001 From: "warren.veerasingam" Date: Sun, 19 Jun 2022 22:36:13 -0500 Subject: [PATCH 3/4] Update readme and website --- README.md | 14 +++++++------- main.go | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5eb459aa..1a77a977 100644 --- a/README.md +++ b/README.md @@ -85,24 +85,24 @@ tfswitch #will automatically switch to terraform version 0.14.4 3. Hit **Enter** to install. ### Install latest implicit version for stable releases 1. Install the latest implicit stable version. -2. Ex: `tfswitch -s 0.13` or `tfswitch --latest-stable 0.13` downloads 0.13.6 (latest) version. +2. Ex: `tfswitch -s 0.13` or `tfswitch --latest-stable 0.13` downloads <1.1.0, >=1.0.0, 1.0 downloads <2.0.0, >=1.0.0. 3. Hit **Enter** to install. ### Install latest implicit version for beta, alpha and release candidates(rc) 1. Install the latest implicit pre-release version. -2. Ex: `tfswitch -p 0.13` or `tfswitch --latest-pre 0.13` downloads 0.13.0-rc1 (latest) version. +2. Ex: `tfswitch -p 0.13` or `tfswitch --latest-pre 0.13` downloads 0.13.0-rc1. 3. Hit **Enter** to install. ### Show latest version only 1. Just show what the latest version is. 2. Run `tfswitch -U` or `tfswitch --show-latest` -3. Hit **Enter** to show. +3. Hit **Enter** to print. ### Show latest implicit version for stable releases 1. Show the latest implicit stable version. -2. Ex: `tfswitch -S 0.13` or `tfswitch --show-latest-stable 0.13` shows 0.13.6 (latest) version. -3. Hit **Enter** to show. +2. Ex: `tfswitch -S 0.13` or `tfswitch --show-latest-stable 0.13` prints 0.15.5 +3. Hit **Enter** to print. ### Show latest implicit version for beta, alpha and release candidates(rc) 1. Show the latest implicit pre-release version. -2. Ex: `tfswitch -P 0.13` or `tfswitch --show-latest-pre 0.13` shows 0.13.0-rc1 (latest) version. -3. Hit **Enter** to show. +2. Ex: `tfswitch -P 0.13` or `tfswitch --show-latest-pre 0.13` prints 0.13.0-rc1. +3. Hit **Enter** to print. ### Use version.tf file If a .tf file with the terraform constrain is included in the current directory, it should automatically download or switch to that terraform version. For example, the following should automatically switch terraform to the latest version: ```ruby diff --git a/main.go b/main.go index 4cdda6ae..502986b8 100644 --- a/main.go +++ b/main.go @@ -54,10 +54,10 @@ func main() { dir := lib.GetCurrentDirectory() custBinPath := getopt.StringLong("bin", 'b', lib.ConvertExecutableExt(defaultBin), "Custom binary path. Ex: tfswitch -b "+lib.ConvertExecutableExt("/Users/username/bin/terraform")) listAllFlag := getopt.BoolLong("list-all", 'l', "List all versions of terraform - including beta and rc") - latestPre := getopt.StringLong("latest-pre", 'p', defaultLatest, "Latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 (latest)") - showLatestPre := getopt.StringLong("show-latest-pre", 'P', defaultLatest, "Show latest pre-release implicit version. Ex: tfswitch --show-latest-pre 0.13 prints 0.13.0-rc1 (latest)") - latestStable := getopt.StringLong("latest-stable", 's', defaultLatest, "Latest implicit version based on a constraint. Ex: tfswitch --latest-stable 0.13.0 downloads 0.13.7 and 0.13 downloads 0.15.5 (latest)") - showLatestStable := getopt.StringLong("show-latest-stable", 'S', defaultLatest, "Show latest implicit version. Ex: tfswitch --show-latest-stable 0.13 prints 0.13.7 (latest)") + latestPre := getopt.StringLong("latest-pre", 'p', defaultLatest, "Latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1") + showLatestPre := getopt.StringLong("show-latest-pre", 'P', defaultLatest, "Show latest pre-release implicit version. Ex: tfswitch --show-latest-pre 0.13 prints 0.13.0-rc1") + latestStable := getopt.StringLong("latest-stable", 's', defaultLatest, "Latest implicit version based on a constraint. Ex: tfswitch --latest-stable 0.13.0 downloads 0.13.7 and 0.13 downloads 0.15.5") + showLatestStable := getopt.StringLong("show-latest-stable", 'S', defaultLatest, "Show latest implicit version. Ex: tfswitch --show-latest-stable 0.13 prints 0.15.5") latestFlag := getopt.BoolLong("latest", 'u', "Get latest stable version") showLatestFlag := getopt.BoolLong("show-latest", 'U', "Show latest stable version") mirrorURL := getopt.StringLong("mirror", 'm', defaultMirror, "Install from a remote API other than the default. Default: "+defaultMirror) @@ -102,7 +102,7 @@ func main() { switch { /* GIVEN A TOML FILE, */ - /* show all terraform version including betas and RCs*/ + /* show all terraform version including betas and RCs */ case *listAllFlag: listAll := true //set list all true - all versions including beta and rc will be displayed installOption(listAll, &binPath, mirrorURL) @@ -110,7 +110,7 @@ func main() { case *latestPre != "": preRelease := true installLatestImplicitVersion(*latestPre, &binPath, mirrorURL, preRelease) - /* show latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 */ + /* show latest pre-release implicit version. Ex: tfswitch --show-latest-pre 0.13 prints 0.13.0-rc1 */ case *showLatestPre != "": preRelease := true showLatestImplicitVersion(*showLatestPre, &binPath, mirrorURL, preRelease) @@ -166,7 +166,7 @@ func main() { preRelease := true installLatestImplicitVersion(*latestPre, custBinPath, mirrorURL, preRelease) - /* show latest pre-release implicit version. Ex: tfswitch --latest-pre 0.13 downloads 0.13.0-rc1 */ + /* show latest pre-release implicit version. Ex: tfswitch --show-latest-pre 0.13 prints 0.13.0-rc1 */ case *showLatestPre != "": preRelease := true showLatestImplicitVersion(*showLatestPre, custBinPath, mirrorURL, preRelease) From 0833c9a22068cfb2134a84aeb171a8d010579ad8 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam" Date: Wed, 22 Jun 2022 12:59:38 -0500 Subject: [PATCH 4/4] make env variable last in Order of precedence --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 502986b8..fca120e2 100644 --- a/main.go +++ b/main.go @@ -141,14 +141,14 @@ func main() { /* if versions.tf file found (IN ADDITION TO A TOML FILE) */ case checkTFModuleFileExist(*chDirPath) && len(args) == 0: installTFProvidedModule(*chDirPath, &binPath, mirrorURL) + /* if terragrunt.hcl file found (IN ADDITION TO A TOML FILE) */ + case fileExists(TGHACLFile) && checkVersionDefinedHCL(&TGHACLFile) && len(args) == 0: + installTGHclFile(&TGHACLFile, &binPath, mirrorURL) /* if Terraform Version environment variable is set */ case checkTFEnvExist() && len(args) == 0 && version == "": tfversion := os.Getenv("TF_VERSION") fmt.Printf("Terraform version environment variable: %s\n", tfversion) installVersion(tfversion, &binPath, mirrorURL) - /* if terragrunt.hcl file found (IN ADDITION TO A TOML FILE) */ - case fileExists(TGHACLFile) && checkVersionDefinedHCL(&TGHACLFile) && len(args) == 0: - installTGHclFile(&TGHACLFile, &binPath, mirrorURL) // if no arg is provided - but toml file is provided case version != "": installVersion(version, &binPath, mirrorURL)