From 4edeaf4d8c0316f9678952dd6a696c95fc9d4bf2 Mon Sep 17 00:00:00 2001 From: "warren.veerasingam@gmail.com" Date: Sun, 14 Nov 2021 21:16:02 -0600 Subject: [PATCH] rename func --- lib/install.go | 2 +- lib/list_versions.go | 2 +- main.go | 25 ++++++++----------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/install.go b/lib/install.go index 5fa6bd1..656a19f 100644 --- a/lib/install.go +++ b/lib/install.go @@ -169,7 +169,7 @@ func ValidVersionFormat(version string) bool { } //Install : Install the provided version in the argument -func Install2(tgversion string, usrBinPath string, mirrorURL string) string { +func Install(tgversion string, usrBinPath string, mirrorURL string) string { if !ValidVersionFormat(tgversion) { fmt.Printf("The provided terraform version format does not exist - %s. Try `tfswitch -l` to see all available versions.\n", tgversion) diff --git a/lib/list_versions.go b/lib/list_versions.go index c804724..a8f135e 100644 --- a/lib/list_versions.go +++ b/lib/list_versions.go @@ -55,7 +55,7 @@ func RemoveDuplicateVersions(elements []string) []string { return result } -func GetAppList2(gruntURLPage string) []string { +func GetAppList(gruntURLPage string) []string { gswitch := http.Client{ Timeout: time.Second * 10, // Maximum of 10 secs [decresing this seem to fail] diff --git a/main.go b/main.go index 6a90c92..f22197b 100644 --- a/main.go +++ b/main.go @@ -28,7 +28,6 @@ import ( ) const ( - //terragruntURL = "https://api.github.com/repos/gruntwork-io/terragrunt/releases?" terragruntURL = "https://github.com/gruntwork-io/terragrunt/releases/download/" defaultBin = "/usr/local/bin/terragrunt" //default bin installation dir rcFilename = ".tgswitchrc" @@ -63,10 +62,6 @@ func main() { } else if *helpFlag { usageMessage() } else { - - //listOfVersions := lib.GetAppList2(proxyUrl) - //fmt.Println(listOfVersions) - //os.Exit(0) installLocation := lib.GetInstallLocation() if _, err := os.Stat(rcfile); err == nil && len(args) == 0 { //if there is a .tgswitchrc file, and no commmand line arguments fmt.Printf("Reading required terragrunt version %s \n", rcFilename) @@ -83,10 +78,10 @@ func main() { lib.ChangeSymlink(*custBinPath, string(tgversion)) os.Exit(0) } - listOfVersions := lib.GetAppList2(proxyUrl) + listOfVersions := lib.GetAppList(proxyUrl) if lib.ValidVersionFormat(tgversion) && lib.VersionExist(tgversion, listOfVersions) { //check if version format is correct && if version exist - lib.Install2(tgversion, *custBinPath, terragruntURL) + lib.Install(tgversion, *custBinPath, terragruntURL) } else { os.Exit(1) } @@ -106,10 +101,10 @@ func main() { lib.ChangeSymlink(*custBinPath, string(tgversion)) os.Exit(0) } - listOfVersions := lib.GetAppList2(proxyUrl) + listOfVersions := lib.GetAppList(proxyUrl) if lib.ValidVersionFormat(tgversion) && lib.VersionExist(tgversion, listOfVersions) { //check if version format is correct && if version exist - lib.Install2(tgversion, *custBinPath, terragruntURL) + lib.Install(tgversion, *custBinPath, terragruntURL) } else { os.Exit(1) } @@ -126,14 +121,12 @@ func main() { } //check if version exist before downloading it - listOfVersions := lib.GetAppList2(proxyUrl) + listOfVersions := lib.GetAppList(proxyUrl) exist := lib.VersionExist(requestedVersion, listOfVersions) if exist { - //installLocation := lib.Install(terragruntURL, requestedVersion, assets, *custBinPath) - installLocation := lib.Install2(requestedVersion, *custBinPath, terragruntURL) + installLocation := lib.Install(requestedVersion, *custBinPath, terragruntURL) fmt.Println("remove later - installLocation:", installLocation) - //lib.AddRecent(requestedVersion) //add to recent file for faster lookup } } else { @@ -143,7 +136,7 @@ func main() { } else if len(args) == 0 { - listOfVersions := lib.GetAppList2(proxyUrl) + listOfVersions := lib.GetAppList(proxyUrl) recentVersions, _ := lib.GetRecentVersions() //get recent versions from RECENT file listOfVersions = append(recentVersions, listOfVersions...) //append recent versions to the top of the list listOfVersions = lib.RemoveDuplicateVersions(listOfVersions) //remove duplicate version @@ -162,9 +155,7 @@ func main() { os.Exit(1) } - //lib.Install(terragruntURL, tgversion, assets, *custBinPath) - lib.Install2(tgversion, *custBinPath, terragruntURL) - //lib.AddRecent(tgversion, installLocation) //add to recent file for faster lookup // moved it to install + lib.Install(tgversion, *custBinPath, terragruntURL) os.Exit(0) } else { usageMessage()