Skip to content

Commit 64f8867

Browse files
committed
uninstall: simplify GetAvailableVersions
1 parent b8a3b6d commit 64f8867

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

cli/uninstall/uninstall.go

+10-15
Original file line numberDiff line numberDiff line change
@@ -208,30 +208,25 @@ func getDefault(program, dir string) (string, error) {
208208
}
209209

210210
// GetAvailableVersions returns a list of the program's versions installed into
211-
// the binDir directory.
212-
func GetAvailableVersions(program string, binDir string) []string {
213-
list := []string{}
214-
re := regexp.MustCompile(
215-
"^" + progRegexp + version.FsSeparator + verRegexp + "$",
216-
)
217-
218-
if binDir == "" {
211+
// the 'dir' directory.
212+
func GetAvailableVersions(program string, dir string) []string {
213+
if dir == "" {
219214
return nil
220215
}
221216

222-
installedPrograms, err := os.ReadDir(binDir)
217+
versionPrefix := filepath.Join(dir, program+version.FsSeparator)
218+
219+
programFiles, err := filepath.Glob(versionPrefix + "*")
223220
if err != nil {
224221
return nil
225222
}
226223

227-
for _, file := range installedPrograms {
228-
matches := util.FindNamedMatches(re, file.Name())
229-
if len(matches) != 0 && matches["prog"] == program {
230-
list = append(list, matches["ver"])
231-
}
224+
versions := []string{}
225+
for _, file := range programFiles {
226+
versions = append(versions, file[len(versionPrefix):])
232227
}
233228

234-
return list
229+
return versions
235230
}
236231

237232
// searchLatestVersion searches for the latest installed version of the program.

0 commit comments

Comments
 (0)