Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display last use in list #204

Merged
merged 2 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions cmd/tenv/subcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ package main
import (
"bytes"
"os"
"path/filepath"
"strconv"
"strings"
"time"

"github.com/tofuutils/tenv/v2/config"
"github.com/tofuutils/tenv/v2/pkg/loghelper"
"github.com/tofuutils/tenv/v2/versionmanager"
"github.com/tofuutils/tenv/v2/versionmanager/lastuse"
"github.com/tofuutils/tenv/v2/versionmanager/semantic"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -188,18 +191,33 @@ func newListCmd(conf *config.Config, versionManager versionmanager.VersionManage
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 {
loghelper.StdDisplay("Can not read used version : " + err.Error())
}
usedVersion := string(bytes.TrimSpace(data))

nilTime := time.Time{}
for _, version := range versions {
if usedVersion == version {
loghelper.StdDisplay(loghelper.Concat("* ", version, " (set by ", filePath, ")"))
} else {
loghelper.StdDisplay(" " + version)
useDate := lastuse.Read(filepath.Join(installPath, version), conf.Displayer)
noUseDate := useDate == nilTime
switch {
case usedVersion == version:
if noUseDate {
loghelper.StdDisplay(loghelper.Concat("* ", version, " (never used, set by ", filePath, ")"))
} else {
loghelper.StdDisplay(loghelper.Concat("* ", version, " (used ", useDate.Format(time.DateOnly), ", set by ", filePath, ")")) //nolint
}
case noUseDate:
loghelper.StdDisplay(loghelper.Concat(" ", version, " (never used)"))
default:
loghelper.StdDisplay(loghelper.Concat(" ", version, " (used ", useDate.Format(time.DateOnly), ")")) //nolint
}
}
if conf.DisplayVerbose {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ require (
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/tools v0.23.0 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
Loading