Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Vaumoron <dvaumoron@gmail.com>
  • Loading branch information
dvaumoron committed Jul 13, 2024
1 parent a95dda3 commit 91c691d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
7 changes: 1 addition & 6 deletions cmd/tenv/subcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,13 @@ func newListCmd(conf *config.Config, versionManager versionmanager.VersionManage
Run: func(_ *cobra.Command, _ []string) {
conf.InitDisplayer(false)

versions, err := versionManager.ListLocal(reverseOrder)
installPath, versions, err := versionManager.ListLocal(reverseOrder)
if err != nil {
loghelper.StdDisplay(err.Error())

return
}

installPath, err := versionManager.InstallPath()
if err != nil && conf.DisplayVerbose {
loghelper.StdDisplay("Can not make install directory : " + err.Error())
}

filePath := versionManager.RootVersionFilePath()
data, err := os.ReadFile(filePath)
if err != nil && conf.DisplayVerbose {
Expand Down
12 changes: 6 additions & 6 deletions versionmanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (m VersionManager) Evaluate(requestedVersion string, proxyCall bool) (strin
}

if !m.conf.ForceRemote {
versions, err := m.ListLocal(predicateInfo.ReverseOrder)
_, versions, err := m.ListLocal(predicateInfo.ReverseOrder)
if err != nil {
m.conf.Displayer.Flush(proxyCall)

Expand Down Expand Up @@ -154,15 +154,15 @@ func (m VersionManager) InstallPath() (string, error) {
return dirPath, os.MkdirAll(dirPath, 0o755)
}

func (m VersionManager) ListLocal(reverseOrder bool) ([]string, error) {
func (m VersionManager) ListLocal(reverseOrder bool) (string, []string, error) {
installPath, err := m.InstallPath()
if err != nil {
return nil, err
return "", nil, err
}

entries, err := os.ReadDir(installPath)
if err != nil {
return nil, err
return "", nil, err
}

versions := make([]string, 0, len(entries))
Expand All @@ -175,7 +175,7 @@ func (m VersionManager) ListLocal(reverseOrder bool) ([]string, error) {
cmpFunc := reversecmp.Reverser[string](semantic.CmpVersion, reverseOrder)
slices.SortFunc(versions, cmpFunc)

return versions, nil
return installPath, versions, nil
}

func (m VersionManager) ListRemote(reverseOrder bool) ([]string, error) {
Expand Down Expand Up @@ -299,7 +299,7 @@ func (m VersionManager) Uninstall(requestedVersion string) error {
return nil
}

versions, err := m.ListLocal(true)
_, versions, err := m.ListLocal(true)
if err != nil {
return err
}
Expand Down

0 comments on commit 91c691d

Please sign in to comment.