Skip to content

Commit

Permalink
uninstall: simplify GetAvailableVersions
Browse files Browse the repository at this point in the history
  • Loading branch information
elhimov committed Jan 22, 2025
1 parent 2c50b24 commit e2e61b8
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions cli/uninstall/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,30 +198,25 @@ func getDefault(program, dir string) (string, error) {
}

// GetAvailableVersions returns a list of the program's versions installed into
// the binDir directory.
func GetAvailableVersions(program string, binDir string) []string {
list := []string{}
re := regexp.MustCompile(
"^" + progRegexp + version.FsSeparator + verRegexp + "$",
)

if binDir == "" {
// the 'dir' directory.
func GetAvailableVersions(program string, dir string) []string {
if dir == "" {
return nil
}

installedPrograms, err := os.ReadDir(binDir)
versionPrefix := filepath.Join(dir, program+version.FsSeparator)

programFiles, err := filepath.Glob(versionPrefix + "*")
if err != nil {
return nil
}

for _, file := range installedPrograms {
matches := util.FindNamedMatches(re, file.Name())
if len(matches) != 0 && matches["prog"] == program {
list = append(list, matches["ver"])
}
versions := []string{}
for _, file := range programFiles {
versions = append(versions, file[len(versionPrefix):])
}

return list
return versions
}

// searchLatestVersion searches for the latest installed version of the program.
Expand Down

0 comments on commit e2e61b8

Please sign in to comment.