Skip to content

Commit

Permalink
rename func
Browse files Browse the repository at this point in the history
  • Loading branch information
warrensbox committed Nov 15, 2021
1 parent fb77b3c commit 4edeaf4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/list_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
25 changes: 8 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit 4edeaf4

Please sign in to comment.