From bd33aa2802c874b983b0d50e440a758b4b7addca Mon Sep 17 00:00:00 2001 From: Chris Gruel Date: Mon, 13 May 2019 07:25:42 -0400 Subject: [PATCH 01/13] support for all terraform versions --- lib/list_versions.go | 4 ++-- lib/list_versions_test.go | 40 +++++++++++++++++++++++++++++++++++++++ main.go | 6 +++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/lib/list_versions.go b/lib/list_versions.go index 192d0306..461d98e6 100644 --- a/lib/list_versions.go +++ b/lib/list_versions.go @@ -37,7 +37,7 @@ func GetTFList(hashiURL string) ([]string, error) { for i := range result { //getting versions from body; should return match /X.X.X/ - r, _ := regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)\/`) + r, _ := regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)(-\w+\d+)?\/`) if r.MatchString(result[i]) { str := r.FindString(result[i]) @@ -95,7 +95,7 @@ func RemoveDuplicateVersions(elements []string) []string { // For example: The 0.1. 2 = invalid func ValidVersionFormat(version string) bool { - semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}\z`) + semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d+)?\z`) semverRegex.MatchString(version) return semverRegex.MatchString(version) } diff --git a/lib/list_versions_test.go b/lib/list_versions_test.go index 21dda71e..ab364af1 100644 --- a/lib/list_versions_test.go +++ b/lib/list_versions_test.go @@ -107,4 +107,44 @@ func TestValidVersionFormat(t *testing.T) { log.Fatalf("Failed to verify version format: %s\n", version) } + version = "1.11.9-beta1" + + valid = lib.ValidVersionFormat(version) + + if valid == true { + t.Log("Valid version format (expected)") + } else { + log.Fatalf("Failed to verify version format: %s\n", version) + } + + version = "0.12.0-rc2" + + valid = lib.ValidVersionFormat(version) + + if valid == true { + t.Log("Valid version format (expected)") + } else { + log.Fatalf("Failed to verify version format: %s\n", version) + } + + version = "1.11.4-boom" + + valid = lib.ValidVersionFormat(version) + + if valid == false { + t.Log("Invalid version format (expected)") + } else { + log.Fatalf("Failed to verify version format: %s\n", version) + } + + version = "1.11.4-1" + + valid = lib.ValidVersionFormat(version) + + if valid == false { + t.Log("Invalid version format (expected)") + } else { + log.Fatalf("Failed to verify version format: %s\n", version) + } + } diff --git a/main.go b/main.go index e44ce125..15e271cc 100644 --- a/main.go +++ b/main.go @@ -69,11 +69,11 @@ func main() { lib.AddRecent(requestedVersion) //add to recent file for faster lookup lib.Install(requestedVersion) } else { - log.Println("Invalid terraform version format. Format should be #.#.# where # is a number. For example, 0.11.7 is a valid version") + log.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions") } } else { - log.Println("Invalid terraform version format. Format should be #.#.# where # is a number. For example, 0.11.7 is a valid version") + log.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions") fmt.Println("Args must be a valid terraform version") usageMessage() } @@ -93,7 +93,7 @@ func main() { lib.AddRecent(string(tfversion)) //add to RECENT file for faster lookup lib.Install(string(tfversion)) } else { - log.Println("Invalid terraform version format. Format should be #.#.# where # is a number. For example, 0.11.7 is a valid version") + log.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions") os.Exit(1) } } else if len(args) == 0 { //if there are no commmand line arguments From 60d48e5504c90654e6c66370a2cc582560dd282f Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Thu, 16 May 2019 23:05:40 -0500 Subject: [PATCH 02/13] Added optional parameter to list-all versions --- lib/list_versions.go | 16 ++++++++++------ main.go | 45 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/lib/list_versions.go b/lib/list_versions.go index 461d98e6..2b80b4ba 100644 --- a/lib/list_versions.go +++ b/lib/list_versions.go @@ -14,7 +14,7 @@ type tfVersionList struct { } //GetTFList : Get the list of available terraform version given the hashicorp url -func GetTFList(hashiURL string) ([]string, error) { +func GetTFList(hashiURL string, listAll bool) ([]string, error) { /* Get list of terraform versions from hashicorp releases */ resp, errURL := http.Get(hashiURL) @@ -37,7 +37,10 @@ func GetTFList(hashiURL string) ([]string, error) { for i := range result { //getting versions from body; should return match /X.X.X/ - r, _ := regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)(-\w+\d+)?\/`) + r, _ := regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)?\/`) + if listAll { + r, _ = regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)(-\w+\d*)?\/`) + } if r.MatchString(result[i]) { str := r.FindString(result[i]) @@ -90,12 +93,13 @@ func RemoveDuplicateVersions(elements []string) []string { } // ValidVersionFormat : returns valid version format -// For example: The 0.1.2 = valid -// For example: The a.1.2 = invalid -// For example: The 0.1. 2 = invalid +// For example: 0.1.2 = valid +// For example: 0.1.2-beta1 = valid +// For example: a.1.2 = invalid +// For example: 0.1. 2 = invalid func ValidVersionFormat(version string) bool { - semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d+)?\z`) + semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d*)?\z`) semverRegex.MatchString(version) return semverRegex.MatchString(version) } diff --git a/main.go b/main.go index 15e271cc..de61ba0b 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main /* -* Version 0.3.0 +* Version 0.5.0 * Compatible with Mac OS X ONLY */ @@ -36,6 +36,7 @@ const ( var version = "0.5.0\n" func main() { + listAllFlag := getopt.BoolLong("list-all", 'l', "list all versions of terraform - including beta and rc") versionFlag := getopt.BoolLong("version", 'v', "displays the version of tfswitch") helpFlag := getopt.BoolLong("help", 'h', "displays help message") _ = versionFlag @@ -54,16 +55,19 @@ func main() { fmt.Printf("\nVersion: %v\n", version) } else if *helpFlag { usageMessage() + } else if *listAllFlag { + listAll := true //set list all true - all versions including beta and rc will be displayed + installOption(listAll) } else { if len(args) == 1 { //if tf version is provided in command line if lib.ValidVersionFormat(args[0]) { requestedVersion := args[0] + listAll := true //set list all true - all versions including beta and rc will be displayed - //check if version exist before downloading it - tflist, _ := lib.GetTFList(hashiURL) - exist := lib.VersionExist(requestedVersion, tflist) + tflist, _ := lib.GetTFList(hashiURL, listAll) //get list of versions + exist := lib.VersionExist(requestedVersion, tflist) //check if version exist before downloading it if exist { lib.AddRecent(requestedVersion) //add to recent file for faster lookup @@ -79,6 +83,7 @@ func main() { } } else if _, err := os.Stat(rcfile); err == nil && len(args) == 0 { //if there is a .tfswitchrc file, and no commmand line arguments + fmt.Println("Reading required terraform version ...") fileContents, err := ioutil.ReadFile(rcfile) if err != nil { @@ -89,7 +94,6 @@ func main() { tfversion := strings.TrimSuffix(string(fileContents), "\n") if lib.ValidVersionFormat(tfversion) { //check if version is correct - fmt.Println("Reading required terraform version ...") lib.AddRecent(string(tfversion)) //add to RECENT file for faster lookup lib.Install(string(tfversion)) } else { @@ -97,8 +101,8 @@ func main() { os.Exit(1) } } else if len(args) == 0 { //if there are no commmand line arguments - - tflist, _ := lib.GetTFList(hashiURL) + listAll := false + tflist, _ := lib.GetTFList(hashiURL, listAll) recentVersions, _ := lib.GetRecentVersions() //get recent versions from RECENT file tflist = append(recentVersions, tflist...) //append recent versions to the top of the list tflist = lib.RemoveDuplicateVersions(tflist) //remove duplicate version @@ -130,3 +134,30 @@ func usageMessage() { getopt.PrintUsage(os.Stderr) fmt.Println("Supply the terraform version as an argument, or choose from a menu") } + +/* installOption : displays & installs tf version */ +/* listAll = true - all versions including beta and rc will be displayed */ +/* listAll = false - only official stable release are displayed */ +func installOption(listAll bool) { + + tflist, _ := lib.GetTFList(hashiURL, listAll) //get list of versions + recentVersions, _ := lib.GetRecentVersions() //get recent versions from RECENT file + tflist = append(recentVersions, tflist...) //append recent versions to the top of the list + tflist = lib.RemoveDuplicateVersions(tflist) //remove duplicate version + + /* prompt user to select version of terraform */ + prompt := promptui.Select{ + Label: "Select Terraform version", + Items: tflist, + } + + _, tfversion, errPrompt := prompt.Run() + + if errPrompt != nil { + log.Printf("Prompt failed %v\n", errPrompt) + os.Exit(1) + } + + lib.AddRecent(tfversion) //add to recent file for faster lookup + lib.Install(tfversion) +} From bbe093dc57d8661caddf3fe64087d8169ea011ee Mon Sep 17 00:00:00 2001 From: Richard Seldon Date: Fri, 17 May 2019 14:54:15 +0900 Subject: [PATCH 03/13] Replace 'teraform' with 'terraform' --- lib/common_test.go | 4 ++-- lib/download_test.go | 8 ++++---- lib/files.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/common_test.go b/lib/common_test.go index 88131077..08606b34 100644 --- a/lib/common_test.go +++ b/lib/common_test.go @@ -34,10 +34,10 @@ func createFile(path string) { func createDirIfNotExist(dir string) { if _, err := os.Stat(dir); os.IsNotExist(err) { - log.Printf("Creating directory for teraform: %v", dir) + log.Printf("Creating directory for terraform: %v", dir) err = os.MkdirAll(dir, 0755) if err != nil { - fmt.Printf("Unable to create directory for teraform: %v", dir) + fmt.Printf("Unable to create directory for terraform: %v", dir) panic(err) } } diff --git a/lib/download_test.go b/lib/download_test.go index 79e26b9b..d21b08e7 100644 --- a/lib/download_test.go +++ b/lib/download_test.go @@ -30,10 +30,10 @@ func TestDownloadFromURL_FileNameMatch(t *testing.T) { // create /.terraform.versions_test/ directory to store code if _, err := os.Stat(installLocation); os.IsNotExist(err) { - log.Printf("Creating directory for teraform: %v", installLocation) + log.Printf("Creating directory for terraform: %v", installLocation) err = os.MkdirAll(installLocation, 0755) if err != nil { - fmt.Printf("Unable to create directory for teraform: %v", installLocation) + fmt.Printf("Unable to create directory for terraform: %v", installLocation) panic(err) } } @@ -95,10 +95,10 @@ func TestDownloadFromURL_FileExist(t *testing.T) { // create /.terraform.versions_test/ directory to store code if _, err := os.Stat(installLocation); os.IsNotExist(err) { - log.Printf("Creating directory for teraform: %v", installLocation) + log.Printf("Creating directory for terraform: %v", installLocation) err = os.MkdirAll(installLocation, 0755) if err != nil { - fmt.Printf("Unable to create directory for teraform: %v", installLocation) + fmt.Printf("Unable to create directory for terraform: %v", installLocation) panic(err) } } diff --git a/lib/files.go b/lib/files.go index 657b3dea..81d63726 100644 --- a/lib/files.go +++ b/lib/files.go @@ -103,10 +103,10 @@ func Unzip(src string, dest string) ([]string, error) { //CreateDirIfNotExist : create directory if directory does not exist func CreateDirIfNotExist(dir string) { if _, err := os.Stat(dir); os.IsNotExist(err) { - log.Printf("Creating directory for teraform: %v", dir) + log.Printf("Creating directory for terraform: %v", dir) err = os.MkdirAll(dir, 0755) if err != nil { - fmt.Printf("Unable to create directory for teraform: %v", dir) + fmt.Printf("Unable to create directory for terraform: %v", dir) panic(err) } } From 8feb329228d9aa38e480211fe32722e106df7f81 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Sat, 18 May 2019 11:57:30 -0500 Subject: [PATCH 04/13] Modified regex to be more readable and stricter --- lib/files_test.go | 9 +++++---- lib/list_versions.go | 9 +++++---- lib/list_versions_test.go | 26 ++++++++++++++------------ main.go | 2 +- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/files_test.go b/lib/files_test.go index aa941f4f..2c6eba94 100644 --- a/lib/files_test.go +++ b/lib/files_test.go @@ -174,7 +174,8 @@ func TestWriteLines(t *testing.T) { installPath := "/.terraform.versions_test/" recentFile := "RECENT" - semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}\z`) + semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d*)?\z`) + //semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}\z`) usr, errCurr := user.Current() if errCurr != nil { @@ -184,7 +185,7 @@ func TestWriteLines(t *testing.T) { createDirIfNotExist(installLocation) - test_array := []string{"0.0.1", "0.0.2", "0.0.3"} + test_array := []string{"0.1.1", "0.0.2", "0.0.3", "0.12.0-rc1", "0.12.0-beta1"} errWrite := lib.WriteLines(test_array, installLocation+recentFile) @@ -243,7 +244,7 @@ func TestWriteLines(t *testing.T) { func TestReadLines(t *testing.T) { installPath := "/.terraform.versions_test/" recentFile := "RECENT" - semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}\z`) + semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d*)?\z`) usr, errCurr := user.Current() if errCurr != nil { @@ -253,7 +254,7 @@ func TestReadLines(t *testing.T) { createDirIfNotExist(installLocation) - test_array := []string{"0.0.1", "0.0.2", "0.0.3"} + test_array := []string{"0.0.1", "0.0.2", "0.0.3", "0.12.0-rc1", "0.12.0-beta1"} var ( file *os.File diff --git a/lib/list_versions.go b/lib/list_versions.go index 2b80b4ba..c8b4a03d 100644 --- a/lib/list_versions.go +++ b/lib/list_versions.go @@ -37,9 +37,10 @@ func GetTFList(hashiURL string, listAll bool) ([]string, error) { for i := range result { //getting versions from body; should return match /X.X.X/ - r, _ := regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)?\/`) + r, _ := regexp.Compile(`\/(\d+\.\d+\.\d+)\/`) + //r, _ := regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)\/`) if listAll { - r, _ = regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)(-\w+\d*)?\/`) + r, _ = regexp.Compile(`\/(\d+\.\d+\.\d+)(-[a-zA-z]+\d*)?\/`) } if r.MatchString(result[i]) { @@ -99,7 +100,7 @@ func RemoveDuplicateVersions(elements []string) []string { // For example: 0.1. 2 = invalid func ValidVersionFormat(version string) bool { - semverRegex := regexp.MustCompile(`\A\d+(\.\d+){2}(-\w+\d*)?\z`) - semverRegex.MatchString(version) + semverRegex := regexp.MustCompile(`^(\d+\.\d+\.\d+)(-[a-zA-z]+\d*)?$`) + return semverRegex.MatchString(version) } diff --git a/lib/list_versions_test.go b/lib/list_versions_test.go index ab364af1..0088f17a 100644 --- a/lib/list_versions_test.go +++ b/lib/list_versions_test.go @@ -15,7 +15,8 @@ const ( // TestGetTFList : Get list from hashicorp func TestGetTFList(t *testing.T) { - list, _ := lib.GetTFList(hashiURL) + listAll := true + list, _ := lib.GetTFList(hashiURL, listAll) val := "0.1.0" var exists bool @@ -42,7 +43,7 @@ func TestGetTFList(t *testing.T) { //TestRemoveDuplicateVersions : test to removed duplicate func TestRemoveDuplicateVersions(t *testing.T) { - test_array := []string{"0.0.1", "0.0.2", "0.0.3", "0.0.1"} + test_array := []string{"0.0.1", "0.0.2", "0.0.3", "0.0.1", "0.12.0-beta1", "0.12.0-beta1"} list := lib.RemoveDuplicateVersions(test_array) @@ -54,6 +55,7 @@ func TestRemoveDuplicateVersions(t *testing.T) { } //TestValidVersionFormat : test if func returns valid version format +// more regex testing at https://rubular.com/r/UvWXui7EU2icSb func TestValidVersionFormat(t *testing.T) { var version string @@ -62,7 +64,7 @@ func TestValidVersionFormat(t *testing.T) { valid := lib.ValidVersionFormat(version) if valid == true { - t.Log("Valid version format (expected)") + t.Logf("Valid version format : %s (expected)", version) } else { log.Fatalf("Failed to verify version format: %s\n", version) } @@ -72,7 +74,7 @@ func TestValidVersionFormat(t *testing.T) { valid = lib.ValidVersionFormat(version) if valid == true { - t.Log("Valid version format (expected)") + t.Logf("Valid version format : %s (expected)", version) } else { log.Fatalf("Failed to verify version format: %s\n", version) } @@ -82,7 +84,7 @@ func TestValidVersionFormat(t *testing.T) { valid = lib.ValidVersionFormat(version) if valid == false { - t.Log("Invalid version format (expected)") + t.Logf("Invalid version format : %s (expected)", version) } else { log.Fatalf("Failed to verify version format: %s\n", version) } @@ -92,7 +94,7 @@ func TestValidVersionFormat(t *testing.T) { valid = lib.ValidVersionFormat(version) if valid == false { - t.Log("Invalid version format (expected)") + t.Logf("Invalid version format : %s (expected)", version) } else { log.Fatalf("Failed to verify version format: %s\n", version) } @@ -102,7 +104,7 @@ func TestValidVersionFormat(t *testing.T) { valid = lib.ValidVersionFormat(version) if valid == false { - t.Log("Invalid version format (expected)") + t.Logf("Invalid version format : %s (expected)", version) } else { log.Fatalf("Failed to verify version format: %s\n", version) } @@ -112,7 +114,7 @@ func TestValidVersionFormat(t *testing.T) { valid = lib.ValidVersionFormat(version) if valid == true { - t.Log("Valid version format (expected)") + t.Logf("Valid version format : %s (expected)", version) } else { log.Fatalf("Failed to verify version format: %s\n", version) } @@ -122,7 +124,7 @@ func TestValidVersionFormat(t *testing.T) { valid = lib.ValidVersionFormat(version) if valid == true { - t.Log("Valid version format (expected)") + t.Logf("Valid version format : %s (expected)", version) } else { log.Fatalf("Failed to verify version format: %s\n", version) } @@ -131,8 +133,8 @@ func TestValidVersionFormat(t *testing.T) { valid = lib.ValidVersionFormat(version) - if valid == false { - t.Log("Invalid version format (expected)") + if valid == true { + t.Logf("Valid version format : %s (expected)", version) } else { log.Fatalf("Failed to verify version format: %s\n", version) } @@ -142,7 +144,7 @@ func TestValidVersionFormat(t *testing.T) { valid = lib.ValidVersionFormat(version) if valid == false { - t.Log("Invalid version format (expected)") + t.Logf("Invalid version format : %s (expected)", version) } else { log.Fatalf("Failed to verify version format: %s\n", version) } diff --git a/main.go b/main.go index de61ba0b..fa04895b 100644 --- a/main.go +++ b/main.go @@ -73,7 +73,7 @@ func main() { lib.AddRecent(requestedVersion) //add to recent file for faster lookup lib.Install(requestedVersion) } else { - log.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions") + log.Println("The provided terraform version does not exist. Try `tfswitch -l` to see all available versions.") } } else { From d993963b5a8e792cad13b6102064519985294197 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Mon, 20 May 2019 12:33:36 -0500 Subject: [PATCH 05/13] Remove redundant code --- main.go | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/main.go b/main.go index fa04895b..6f060183 100644 --- a/main.go +++ b/main.go @@ -101,27 +101,9 @@ func main() { os.Exit(1) } } else if len(args) == 0 { //if there are no commmand line arguments - listAll := false - tflist, _ := lib.GetTFList(hashiURL, listAll) - recentVersions, _ := lib.GetRecentVersions() //get recent versions from RECENT file - tflist = append(recentVersions, tflist...) //append recent versions to the top of the list - tflist = lib.RemoveDuplicateVersions(tflist) //remove duplicate version - - /* prompt user to select version of terraform */ - prompt := promptui.Select{ - Label: "Select Terraform version", - Items: tflist, - } - - _, tfversion, errPrompt := prompt.Run() - if errPrompt != nil { - log.Printf("Prompt failed %v\n", errPrompt) - os.Exit(1) - } - - lib.AddRecent(tfversion) //add to recent file for faster lookup - lib.Install(tfversion) + listAll := false //set list all false - only official release will be displayed + installOption(listAll) } else { usageMessage() @@ -143,7 +125,7 @@ func installOption(listAll bool) { tflist, _ := lib.GetTFList(hashiURL, listAll) //get list of versions recentVersions, _ := lib.GetRecentVersions() //get recent versions from RECENT file tflist = append(recentVersions, tflist...) //append recent versions to the top of the list - tflist = lib.RemoveDuplicateVersions(tflist) //remove duplicate version + //tflist = lib.RemoveDuplicateVersions(tflist) //remove duplicate version /* prompt user to select version of terraform */ prompt := promptui.Select{ @@ -161,3 +143,8 @@ func installOption(listAll bool) { lib.AddRecent(tfversion) //add to recent file for faster lookup lib.Install(tfversion) } + +// func appendRecent(tflist []string) { + +// for _, vals := range +// } From a55e6bf34f016ef10e5cb0affc3d3a3af80ce160 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Mon, 20 May 2019 14:00:04 -0500 Subject: [PATCH 06/13] *recent to for recent versions. Options to install all versions including betas and RCs --- .goreleaser.yml | 4 ++-- lib/install.go | 14 +++++++++++++- lib/list_versions.go | 9 +++++---- main.go | 8 ++------ 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index e29188c0..a8ef5d5a 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -72,8 +72,8 @@ brew: skip_upload: false # Packages that conflict with your package. - # conflicts: - # - terraform + conflicts: + - terraform # So you can `brew test` your formula. # Default is empty. diff --git a/lib/install.go b/lib/install.go index b5808b6c..fe3b3bef 100644 --- a/lib/install.go +++ b/lib/install.go @@ -54,6 +54,11 @@ func init() { //Install : Install the provided version in the argument func Install(tfversion string) { + if !ValidVersionFormat(tfversion) { + fmt.Printf("The provided terraform version does not exist - %s. Try `tfswitch -l` to see all available versions.\n", tfversion) + os.Exit(0) + } + goarch := runtime.GOARCH goos := runtime.GOOS @@ -155,6 +160,7 @@ func GetRecentVersions() ([]string, error) { if fileExist { lines, errRead := ReadLines(installLocation + recentFile) + appendRecent := []string{} if errRead != nil { fmt.Printf("Error: %s\n", errRead) @@ -162,13 +168,19 @@ func GetRecentVersions() ([]string, error) { } for _, line := range lines { + /* checks if versions in the recent file are valid. + If any version is invalid, it will be consider dirty + and the recent file will be removed + */ if !ValidVersionFormat(line) { RemoveFiles(installLocation + recentFile) return nil, errRead } + + appendRecent = append(appendRecent, fmt.Sprintf("%s *recent", line)) } - return lines, nil + return appendRecent, nil } return nil, nil diff --git a/lib/list_versions.go b/lib/list_versions.go index c8b4a03d..6991cf2a 100644 --- a/lib/list_versions.go +++ b/lib/list_versions.go @@ -79,14 +79,15 @@ func RemoveDuplicateVersions(elements []string) []string { encountered := map[string]bool{} result := []string{} - for v := range elements { - if encountered[elements[v]] == true { + for _, val := range elements { + versionOnly := strings.Trim(val, " *recent") + if encountered[versionOnly] == true { // Do not add duplicate. } else { // Record this element as an encountered element. - encountered[elements[v]] = true + encountered[versionOnly] = true // Append to result slice. - result = append(result, elements[v]) + result = append(result, val) } } // Return the new slice. diff --git a/main.go b/main.go index 6f060183..e686a0bb 100644 --- a/main.go +++ b/main.go @@ -125,7 +125,7 @@ func installOption(listAll bool) { tflist, _ := lib.GetTFList(hashiURL, listAll) //get list of versions recentVersions, _ := lib.GetRecentVersions() //get recent versions from RECENT file tflist = append(recentVersions, tflist...) //append recent versions to the top of the list - //tflist = lib.RemoveDuplicateVersions(tflist) //remove duplicate version + tflist = lib.RemoveDuplicateVersions(tflist) //remove duplicate version /* prompt user to select version of terraform */ prompt := promptui.Select{ @@ -134,6 +134,7 @@ func installOption(listAll bool) { } _, tfversion, errPrompt := prompt.Run() + tfversion = strings.Trim(tfversion, " *recent") //trim versions with the word *recent included if errPrompt != nil { log.Printf("Prompt failed %v\n", errPrompt) @@ -143,8 +144,3 @@ func installOption(listAll bool) { lib.AddRecent(tfversion) //add to recent file for faster lookup lib.Install(tfversion) } - -// func appendRecent(tflist []string) { - -// for _, vals := range -// } From f628fc9e9101fcd99fd2e044ca6854532ff0d705 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Mon, 20 May 2019 23:07:34 -0500 Subject: [PATCH 07/13] If StatusCode return != 200 exit program immediately --- README.md | 8 ++++++++ lib/download.go | 21 ++++++++++++++------- lib/install.go | 12 +++++++++--- main.go | 17 +++++++---------- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index fa57a97c..bbc9a0e6 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,14 @@ The most recently selected versions are presented at the top of the dropdown. 2. For example, `tfswitch 0.10.5` for version 0.10.5 of terraform. 3. Hit **Enter** to switch. +### See all versions including beta, alpha and release candidates(rc) +drawing + +1. Display all versions including beta, alpha and release candidates(rc). +2. For example, `tfswitch -l` or `tfswitch --list-all` to see all versions. +3. Hit **Enter** to select the desired version. + + ### Use .tfswitchrc file 1. Create a `.tfswitchrc` file containing the desired version diff --git a/lib/download.go b/lib/download.go index d7afa8fc..b2477b49 100644 --- a/lib/download.go +++ b/lib/download.go @@ -14,21 +14,28 @@ func DownloadFromURL(installLocation string, url string) (string, error) { fileName := tokens[len(tokens)-1] fmt.Println("Downloading", url, "to", fileName) fmt.Println("Downloading ...") - // TODO: check file existence first with io.IsExist - output, err := os.Create(installLocation + fileName) - if err != nil { - fmt.Println("Error while creating", installLocation+fileName, "-", err) - return "", err - } - defer output.Close() response, err := http.Get(url) + if err != nil { fmt.Println("Error while downloading", url, "-", err) return "", err } defer response.Body.Close() + if response.StatusCode != 200 { + //Sometimes hashicorp terraform file names are not consistent + //For example 0.12.0-alpha4 naming convention in the release repo is not consistent + return "", fmt.Errorf("Unable to download from %s\nPlease download manually from https://releases.hashicorp.com/terraform/", url) + } + + output, err := os.Create(installLocation + fileName) + if err != nil { + fmt.Println("Error while creating", installLocation+fileName, "-", err) + return "", err + } + defer output.Close() + n, err := io.Copy(output, response.Body) if err != nil { fmt.Println("Error while downloading", url, "-", err) diff --git a/lib/install.go b/lib/install.go index fe3b3bef..8e615796 100644 --- a/lib/install.go +++ b/lib/install.go @@ -55,8 +55,8 @@ func init() { func Install(tfversion string) { if !ValidVersionFormat(tfversion) { - fmt.Printf("The provided terraform version does not exist - %s. Try `tfswitch -l` to see all available versions.\n", tfversion) - os.Exit(0) + fmt.Printf("The provided terraform version format does not exist - %s. Try `tfswitch -l` to see all available versions.\n", tfversion) + os.Exit(1) } goarch := runtime.GOARCH @@ -84,7 +84,12 @@ func Install(tfversion string) { /* if selected version already exist, */ /* proceed to download it from the hashicorp release page */ url := hashiURL + tfversion + "/" + installVersion + tfversion + "_" + goos + "_" + goarch + ".zip" - zipFile, _ := DownloadFromURL(installLocation, url) + zipFile, errDownload := DownloadFromURL(installLocation, url) + + if errDownload != nil { + fmt.Println(errDownload) + os.Exit(1) + } /* unzip the downloaded zipfile */ _, errUnzip := Unzip(zipFile, installLocation) @@ -110,6 +115,7 @@ func Install(tfversion string) { /* set symlink to desired version */ CreateSymlink(installLocation+installVersion+tfversion, installedBinPath) fmt.Printf("Switched terraform to version %q \n", tfversion) + AddRecent(tfversion) //add to recent file for faster lookup os.Exit(0) } diff --git a/main.go b/main.go index e686a0bb..d7231b62 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main /* -* Version 0.5.0 +* Version 0.6.0 * Compatible with Mac OS X ONLY */ @@ -33,7 +33,7 @@ const ( hashiURL = "https://releases.hashicorp.com/terraform/" ) -var version = "0.5.0\n" +var version = "0.6.0\n" func main() { listAllFlag := getopt.BoolLong("list-all", 'l', "list all versions of terraform - including beta and rc") @@ -70,14 +70,13 @@ func main() { exist := lib.VersionExist(requestedVersion, tflist) //check if version exist before downloading it if exist { - lib.AddRecent(requestedVersion) //add to recent file for faster lookup lib.Install(requestedVersion) } else { - log.Println("The provided terraform version does not exist. Try `tfswitch -l` to see all available versions.") + fmt.Println("The provided terraform version does not exist. Try `tfswitch -l` to see all available versions.") } } else { - log.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions") + fmt.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions") fmt.Println("Args must be a valid terraform version") usageMessage() } @@ -87,17 +86,16 @@ func main() { fileContents, err := ioutil.ReadFile(rcfile) if err != nil { - log.Println("Failed to read .tfswitchrc file. Follow the README.md instructions for setup. https://github.com/warrensbox/terraform-switcher/blob/master/README.md") - log.Printf("Error: %s\n", err) + fmt.Println("Failed to read .tfswitchrc file. Follow the README.md instructions for setup. https://github.com/warrensbox/terraform-switcher/blob/master/README.md") + fmt.Printf("Error: %s\n", err) os.Exit(1) } tfversion := strings.TrimSuffix(string(fileContents), "\n") if lib.ValidVersionFormat(tfversion) { //check if version is correct - lib.AddRecent(string(tfversion)) //add to RECENT file for faster lookup lib.Install(string(tfversion)) } else { - log.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions") + fmt.Println("Invalid terraform version format. Format should be #.#.# or #.#.#-@# where # is numbers and @ is word characters. For example, 0.11.7 and 0.11.9-beta1 are valid versions") os.Exit(1) } } else if len(args) == 0 { //if there are no commmand line arguments @@ -141,6 +139,5 @@ func installOption(listAll bool) { os.Exit(1) } - lib.AddRecent(tfversion) //add to recent file for faster lookup lib.Install(tfversion) } From fcdc24bc76113651c24d2b3edcc3cd2875801c04 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Mon, 20 May 2019 23:54:02 -0500 Subject: [PATCH 08/13] updated test cases --- lib/download_test.go | 81 ++++++++++++++++++++++++++++++++++++++------ lib/install.go | 11 ++++-- lib/list_versions.go | 14 ++++++-- main.go | 6 ++-- 4 files changed, 93 insertions(+), 19 deletions(-) diff --git a/lib/download_test.go b/lib/download_test.go index d21b08e7..f4785ae7 100644 --- a/lib/download_test.go +++ b/lib/download_test.go @@ -39,11 +39,16 @@ func TestDownloadFromURL_FileNameMatch(t *testing.T) { } /* test download lowest terraform version */ - lowestVersion := "0.0.1" + lowestVersion := "0.1.0" url := hashiURL + lowestVersion + "/" + installVersion + lowestVersion + macOS expectedFile := usr.HomeDir + installPath + installVersion + lowestVersion + macOS - installedFile, _ := lib.DownloadFromURL(installLocation, url) + installedFile, errDownload := lib.DownloadFromURL(installLocation, url) + + if errDownload != nil { + t.Logf("Expected file name %v to be downloaded", expectedFile) + t.Error("Download not possible (unexpected)") + } if installedFile == expectedFile { t.Logf("Expected file %v", expectedFile) @@ -52,7 +57,7 @@ func TestDownloadFromURL_FileNameMatch(t *testing.T) { } else { t.Logf("Expected file %v", expectedFile) t.Logf("Downloaded file %v", installedFile) - t.Error("Download file mismatches expected file") + t.Error("Download file mismatches expected file (unexpected)") } /* test download latest terraform version */ @@ -60,7 +65,12 @@ func TestDownloadFromURL_FileNameMatch(t *testing.T) { url = hashiURL + latestVersion + "/" + installVersion + latestVersion + macOS expectedFile = usr.HomeDir + installPath + installVersion + latestVersion + macOS - installedFile, _ = lib.DownloadFromURL(installLocation, url) + installedFile, errDownload = lib.DownloadFromURL(installLocation, url) + + if errDownload != nil { + t.Logf("Expected file name %v to be downloaded", expectedFile) + t.Error("Download not possible (unexpected)") + } if installedFile == expectedFile { t.Logf("Expected file name %v", expectedFile) @@ -69,7 +79,7 @@ func TestDownloadFromURL_FileNameMatch(t *testing.T) { } else { t.Logf("Expected file name %v", expectedFile) t.Logf("Downloaded file name %v", installedFile) - t.Error("Downoad file name mismatches expected file") + t.Error("Dowload file name mismatches expected file (unexpected)") } cleanUp(installLocation) @@ -104,11 +114,16 @@ func TestDownloadFromURL_FileExist(t *testing.T) { } /* test download lowest terraform version */ - lowestVersion := "0.0.1" + lowestVersion := "0.1.0" url := hashiURL + lowestVersion + "/" + installVersion + lowestVersion + macOS expectedFile := usr.HomeDir + installPath + installVersion + lowestVersion + macOS - installedFile, _ := lib.DownloadFromURL(installLocation, url) + installedFile, errDownload := lib.DownloadFromURL(installLocation, url) + + if errDownload != nil { + t.Logf("Expected file name %v to be downloaded", expectedFile) + t.Error("Download not possible (unexpected)") + } if checkFileExist(expectedFile) { t.Logf("Expected file %v", expectedFile) @@ -117,7 +132,7 @@ func TestDownloadFromURL_FileExist(t *testing.T) { } else { t.Logf("Expected file %v", expectedFile) t.Logf("Downloaded file %v", installedFile) - t.Error("Downoad file mismatches expected file") + t.Error("Download file mismatches expected file (unexpected)") } /* test download latest terraform version */ @@ -125,7 +140,12 @@ func TestDownloadFromURL_FileExist(t *testing.T) { url = hashiURL + latestVersion + "/" + installVersion + latestVersion + macOS expectedFile = usr.HomeDir + installPath + installVersion + latestVersion + macOS - installFile, _ = lib.DownloadFromURL(installLocation, url) + installFile, errDownload = lib.DownloadFromURL(installLocation, url) + + if errDownload != nil { + t.Logf("Expected file name %v to be downloaded", expectedFile) + t.Error("Download not possible (unexpected)") + } if checkFileExist(expectedFile) { t.Logf("Expected file %v", expectedFile) @@ -134,12 +154,53 @@ func TestDownloadFromURL_FileExist(t *testing.T) { } else { t.Logf("Expected file %v", expectedFile) t.Logf("Downloaded file %v", installFile) - t.Error("Downoad file mismatches expected file") + t.Error("Download file mismatches expected file (unexpected)") + } + + cleanUp(installLocation) +} + +// TestInvalidURL : Invalid url should throw an error +func TestInvalidURL(t *testing.T) { + + hashiURL := "https://releases.hashicorp.com/terraform/" + installVersion := "terraform_" + installPath := "/.terraform.versions_test/" + macOS := "_darwin_amd64.zip" + invalidVersion := "0.11.7-nonexistent" + + // get current user + usr, errCurr := user.Current() + if errCurr != nil { + log.Fatal(errCurr) + } + + fmt.Printf("Current user: %v \n", usr.HomeDir) + installLocation := usr.HomeDir + installPath + + // create /.terraform.versions_test/ directory to store code + if _, err := os.Stat(installLocation); os.IsNotExist(err) { + log.Printf("Creating directory for terraform: %v\n", installLocation) + err = os.MkdirAll(installLocation, 0755) + if err != nil { + fmt.Printf("Unable to create directory for terraform: %v\n", installLocation) + panic(err) + } + } + + url := hashiURL + invalidVersion + "/" + installVersion + invalidVersion + macOS + //expectedFile := usr.HomeDir + installPath + installVersion + invalidVersion + macOS + _, errDownload := lib.DownloadFromURL(installLocation, url) + + if errDownload != nil { + t.Logf("Unable to download from %s - invalid url or version (expected)\n", url) + t.Logf("Download not possible (expected)") } cleanUp(installLocation) } +// TestDownloadFromURL_Valid : Test if https://releases.hashicorp.com/terraform/ is still valid func TestDownloadFromURL_Valid(t *testing.T) { hashiURL := "https://releases.hashicorp.com/terraform/" diff --git a/lib/install.go b/lib/install.go index 8e615796..618269d7 100644 --- a/lib/install.go +++ b/lib/install.go @@ -78,6 +78,7 @@ func Install(tfversion string) { /* set symlink to desired version */ CreateSymlink(installLocation+installVersion+tfversion, installedBinPath) fmt.Printf("Switched terraform to version %q \n", tfversion) + AddRecent(tfversion) //add to recent file for faster lookup os.Exit(0) } @@ -86,6 +87,7 @@ func Install(tfversion string) { url := hashiURL + tfversion + "/" + installVersion + tfversion + "_" + goos + "_" + goarch + ".zip" zipFile, errDownload := DownloadFromURL(installLocation, url) + /* If unable to download file from url, exit(1) immediately */ if errDownload != nil { fmt.Println(errDownload) os.Exit(1) @@ -166,7 +168,7 @@ func GetRecentVersions() ([]string, error) { if fileExist { lines, errRead := ReadLines(installLocation + recentFile) - appendRecent := []string{} + outputRecent := []string{} if errRead != nil { fmt.Printf("Error: %s\n", errRead) @@ -183,10 +185,13 @@ func GetRecentVersions() ([]string, error) { return nil, errRead } - appendRecent = append(appendRecent, fmt.Sprintf("%s *recent", line)) + /* output can be confusing since it displays the 3 most recent used terraform version + append the string *recent to the output to make it more user friendly + */ + outputRecent = append(outputRecent, fmt.Sprintf("%s *recent", line)) } - return appendRecent, nil + return outputRecent, nil } return nil, nil diff --git a/lib/list_versions.go b/lib/list_versions.go index 6991cf2a..c7ca1fb2 100644 --- a/lib/list_versions.go +++ b/lib/list_versions.go @@ -36,10 +36,13 @@ func GetTFList(hashiURL string, listAll bool) ([]string, error) { var tfVersionList tfVersionList for i := range result { - //getting versions from body; should return match /X.X.X/ + // Getting versions from body; should return match /X.X.X/ where X is a number + // Follow https://semver.org/spec/v2.0.0.html r, _ := regexp.Compile(`\/(\d+\.\d+\.\d+)\/`) - //r, _ := regexp.Compile(`\/(\d+)(\.)(\d+)(\.)(\d+)\/`) if listAll { + // Getting versions from body; should return match /X.X.X-@/ where X is a number,@ is a word character between a-z or A-Z + // Follow https://semver.org/spec/v1.0.0-beta.html + // Check regular expression at https://rubular.com/r/ju3PxbaSBALpJB r, _ = regexp.Compile(`\/(\d+\.\d+\.\d+)(-[a-zA-z]+\d*)?\/`) } @@ -95,12 +98,17 @@ func RemoveDuplicateVersions(elements []string) []string { } // ValidVersionFormat : returns valid version format -// For example: 0.1.2 = valid +/* For example: 0.1.2 = valid // For example: 0.1.2-beta1 = valid +// For example: 0.1.2-alpha = valid // For example: a.1.2 = invalid // For example: 0.1. 2 = invalid +*/ func ValidVersionFormat(version string) bool { + // Getting versions from body; should return match /X.X.X-@/ where X is a number,@ is a word character between a-z or A-Z + // Follow https://semver.org/spec/v1.0.0-beta.html + // Check regular expression at https://rubular.com/r/ju3PxbaSBALpJB semverRegex := regexp.MustCompile(`^(\d+\.\d+\.\d+)(-[a-zA-z]+\d*)?$`) return semverRegex.MatchString(version) diff --git a/main.go b/main.go index d7231b62..523ef183 100644 --- a/main.go +++ b/main.go @@ -63,9 +63,9 @@ func main() { if len(args) == 1 { //if tf version is provided in command line if lib.ValidVersionFormat(args[0]) { - requestedVersion := args[0] - listAll := true //set list all true - all versions including beta and rc will be displayed + requestedVersion := args[0] + listAll := true //set list all true - all versions including beta and rc will be displayed tflist, _ := lib.GetTFList(hashiURL, listAll) //get list of versions exist := lib.VersionExist(requestedVersion, tflist) //check if version exist before downloading it @@ -132,7 +132,7 @@ func installOption(listAll bool) { } _, tfversion, errPrompt := prompt.Run() - tfversion = strings.Trim(tfversion, " *recent") //trim versions with the word *recent included + tfversion = strings.Trim(tfversion, " *recent") //trim versions with the string " *recent" appended if errPrompt != nil { log.Printf("Prompt failed %v\n", errPrompt) From a476ee38cf2aae2f2729d25873970bf2743f832b Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Mon, 20 May 2019 23:54:53 -0500 Subject: [PATCH 09/13] bumped version --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 98eace89..bb82e304 100644 --- a/version +++ b/version @@ -1 +1 @@ -RELEASE_VERSION=0.5 \ No newline at end of file +RELEASE_VERSION=0.6 \ No newline at end of file From 2f2db925357f881bcf2dfbe6e312c5b8fa043096 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Wed, 22 May 2019 00:53:40 -0500 Subject: [PATCH 10/13] updated documentation --- README.md | 3 ++- docs/_site/additional.html | 14 ++++++-------- docs/_site/index.html | 14 ++++++-------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index bbc9a0e6..4a22f259 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ The most recently selected versions are presented at the top of the dropdown. 3. Hit **Enter** to switch. ### See all versions including beta, alpha and release candidates(rc) -drawing +drawing 1. Display all versions including beta, alpha and release candidates(rc). 2. For example, `tfswitch -l` or `tfswitch --list-all` to see all versions. @@ -66,6 +66,7 @@ The most recently selected versions are presented at the top of the dropdown. ### Use .tfswitchrc file +drawing 1. Create a `.tfswitchrc` file containing the desired version 2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform diff --git a/docs/_site/additional.html b/docs/_site/additional.html index 761b1a6e..396f72c2 100644 --- a/docs/_site/additional.html +++ b/docs/_site/additional.html @@ -18,14 +18,12 @@ - - +{"description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebPage","url":"/additional.html","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"tfswitch","@context":"http://schema.org"} - + @@ -43,8 +41,8 @@
- - + +

Logo @@ -59,8 +57,8 @@

diff --git a/docs/_site/index.html b/docs/_site/index.html index 1c2e7039..830610b4 100644 --- a/docs/_site/index.html +++ b/docs/_site/index.html @@ -18,14 +18,12 @@ - - +{"name":"tfswitch","description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebSite","url":"/","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"Terraform Switcher","@context":"http://schema.org"} - + @@ -43,8 +41,8 @@
- - + +

Logo @@ -59,8 +57,8 @@

From 761573f99ebb8bec791e734a7e0dfeb26930e276 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Wed, 22 May 2019 11:14:10 -0500 Subject: [PATCH 11/13] - option to install any version (documentation) --- docs/_site/additional.html | 2 +- docs/_site/index.html | 18 ++++++++++++++---- docs/_site/index.md | 15 ++++++++++++--- docs/index.md | 15 ++++++++++++--- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/docs/_site/additional.html b/docs/_site/additional.html index 396f72c2..6145da03 100644 --- a/docs/_site/additional.html +++ b/docs/_site/additional.html @@ -23,7 +23,7 @@ {"description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebPage","url":"/additional.html","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"tfswitch","@context":"http://schema.org"} - + diff --git a/docs/_site/index.html b/docs/_site/index.html index 830610b4..b6cc559b 100644 --- a/docs/_site/index.html +++ b/docs/_site/index.html @@ -23,7 +23,7 @@ {"name":"tfswitch","description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebSite","url":"/","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"Terraform Switcher","@context":"http://schema.org"} - + @@ -119,12 +119,22 @@

Supply version on command line

  • Hit Enter to switch.
  • +

    See all versions including beta, alpha and release candidates(rc)

    +

    drawing

    + +
      +
    1. Display all versions including beta, alpha and release candidates(rc).
    2. +
    3. For example, tfswitch -l or tfswitch --list-all to see all versions.
    4. +
    5. Hit Enter to select the desired version.
    6. +
    +

    Use .tfswitchrc file

    +

    drawing

      -
    1. Create a .tfswitchrc file containing the desired version
    2. -
    3. For example, echo "0.10.5" >> .tfswitchrc for version 0.10.5 of terraform
    4. -
    5. Run the command tfswitch in the same directory as your .tfswitchrc
    6. +
    7. Create a .tfswitchrc file containing the desired version.
    8. +
    9. For example, echo "0.10.5" >> .tfswitchrc for version 0.10.5 of terraform.
    10. +
    11. Run the command tfswitch in the same directory as your .tfswitchrc.

    Automatically switch with bash

    diff --git a/docs/_site/index.md b/docs/_site/index.md index c1ab1a5d..3b677ef3 100644 --- a/docs/_site/index.md +++ b/docs/_site/index.md @@ -51,11 +51,20 @@ The most recently selected versions are presented at the top of the dropdown. 2. For example, `tfswitch 0.10.5` for version 0.10.5 of terraform. 3. Hit **Enter** to switch. +### See all versions including beta, alpha and release candidates(rc) +drawing + +1. Display all versions including beta, alpha and release candidates(rc). +2. For example, `tfswitch -l` or `tfswitch --list-all` to see all versions. +3. Hit **Enter** to select the desired version. + + ### Use .tfswitchrc file +drawing -1. Create a `.tfswitchrc` file containing the desired version -2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform -3. Run the command `tfswitch` in the same directory as your `.tfswitchrc` +1. Create a `.tfswitchrc` file containing the desired version. +2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform. +3. Run the command `tfswitch` in the same directory as your `.tfswitchrc`. **Automatically switch with bash** diff --git a/docs/index.md b/docs/index.md index c1ab1a5d..3b677ef3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -51,11 +51,20 @@ The most recently selected versions are presented at the top of the dropdown. 2. For example, `tfswitch 0.10.5` for version 0.10.5 of terraform. 3. Hit **Enter** to switch. +### See all versions including beta, alpha and release candidates(rc) +drawing + +1. Display all versions including beta, alpha and release candidates(rc). +2. For example, `tfswitch -l` or `tfswitch --list-all` to see all versions. +3. Hit **Enter** to select the desired version. + + ### Use .tfswitchrc file +drawing -1. Create a `.tfswitchrc` file containing the desired version -2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform -3. Run the command `tfswitch` in the same directory as your `.tfswitchrc` +1. Create a `.tfswitchrc` file containing the desired version. +2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform. +3. Run the command `tfswitch` in the same directory as your `.tfswitchrc`. **Automatically switch with bash** From 53c4a658dbed6fd2f05b5ffb643fb2bd96cbbf88 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Wed, 22 May 2019 11:26:42 -0500 Subject: [PATCH 12/13] Increased documentation gif window --- docs/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 3b677ef3..241adc85 100644 --- a/docs/index.md +++ b/docs/index.md @@ -52,7 +52,7 @@ The most recently selected versions are presented at the top of the dropdown. 3. Hit **Enter** to switch. ### See all versions including beta, alpha and release candidates(rc) -drawing +drawing 1. Display all versions including beta, alpha and release candidates(rc). 2. For example, `tfswitch -l` or `tfswitch --list-all` to see all versions. @@ -60,7 +60,7 @@ The most recently selected versions are presented at the top of the dropdown. ### Use .tfswitchrc file -drawing +drawing 1. Create a `.tfswitchrc` file containing the desired version. 2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform. From ee98a7739a7b4f88e5d34cedb1103b7b11d07bb1 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Wed, 22 May 2019 11:27:13 -0500 Subject: [PATCH 13/13] Increased documentation gif window --- docs/_site/additional.html | 2 +- docs/_site/index.html | 6 +++--- docs/_site/index.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/_site/additional.html b/docs/_site/additional.html index 6145da03..8b8eb021 100644 --- a/docs/_site/additional.html +++ b/docs/_site/additional.html @@ -23,7 +23,7 @@ {"description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebPage","url":"/additional.html","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"tfswitch","@context":"http://schema.org"} - + diff --git a/docs/_site/index.html b/docs/_site/index.html index b6cc559b..b4797389 100644 --- a/docs/_site/index.html +++ b/docs/_site/index.html @@ -23,7 +23,7 @@ {"name":"tfswitch","description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebSite","url":"/","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"Terraform Switcher","@context":"http://schema.org"} - + @@ -120,7 +120,7 @@

    Supply version on command line

    See all versions including beta, alpha and release candidates(rc)

    -

    drawing

    +

    drawing

    1. Display all versions including beta, alpha and release candidates(rc).
    2. @@ -129,7 +129,7 @@

      See all

    Use .tfswitchrc file

    -

    drawing

    +

    drawing

    1. Create a .tfswitchrc file containing the desired version.
    2. diff --git a/docs/_site/index.md b/docs/_site/index.md index 3b677ef3..241adc85 100644 --- a/docs/_site/index.md +++ b/docs/_site/index.md @@ -52,7 +52,7 @@ The most recently selected versions are presented at the top of the dropdown. 3. Hit **Enter** to switch. ### See all versions including beta, alpha and release candidates(rc) -drawing +drawing 1. Display all versions including beta, alpha and release candidates(rc). 2. For example, `tfswitch -l` or `tfswitch --list-all` to see all versions. @@ -60,7 +60,7 @@ The most recently selected versions are presented at the top of the dropdown. ### Use .tfswitchrc file -drawing +drawing 1. Create a `.tfswitchrc` file containing the desired version. 2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform.