Skip to content

Commit

Permalink
pick the latest in order for dev-latest (#180)
Browse files Browse the repository at this point in the history
* pick right order for dev-latest
  • Loading branch information
kevincobain2000 committed Feb 10, 2024
1 parent 55562ca commit a6dba07
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion helpers.go
Expand Up @@ -199,6 +199,9 @@ func (gb *GoBrew) judgeVersion(version string) string {
return gb.judgeVersion(modVersion)
}
groupedVersions := gb.ListRemoteVersions(false) // donot print

// latest will pick the latest version excluding rc and beta
// dev-latest will first remove rc and beta from the list of versions and then pick the latest version
if version == "latest" || version == "dev-latest" {
groupedVersionKeys := make([]string, 0, len(groupedVersions))
for groupedVersionKey := range groupedVersions {
Expand All @@ -224,7 +227,16 @@ func (gb *GoBrew) judgeVersion(version string) string {
if len(judgedVersions) == 0 {
return "None"
}
return judgedVersions[len(judgedVersions)-1]
// Filter versions containing "rc" or "beta"
filteredVersions := gb.filterVersions(judgedVersions, []string{"rc", "beta"})

// Get the last element of the filtered slice
var lastVersion string
if len(filteredVersions) > 0 {
lastVersion = filteredVersions[len(filteredVersions)-1]
}

return lastVersion
}

// loop in reverse
Expand Down Expand Up @@ -313,6 +325,20 @@ func (gb *GoBrew) getVersionDir(version string) string {
return filepath.Join(gb.versionsDir, version)
}

// filterVersions returns a new slice containing only the elements that contain any of the substrings in contains
func (gb *GoBrew) filterVersions(versions []string, contains []string) []string {
var filtered []string
for _, version := range versions {
for _, contain := range contains {
if strings.Contains(version, contain) {
filtered = append(filtered, version)
break // Move to the next version after the first match
}
}
}
return filtered
}

func (gb *GoBrew) downloadAndExtract(version string) {
tarName := "go" + version + "." + gb.getArch() + tarNameExt

Expand Down

0 comments on commit a6dba07

Please sign in to comment.