diff --git a/cmd/tenv/subcmd.go b/cmd/tenv/subcmd.go index 2933c476..16293d83 100644 --- a/cmd/tenv/subcmd.go +++ b/cmd/tenv/subcmd.go @@ -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" @@ -188,6 +191,11 @@ 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 { @@ -195,11 +203,21 @@ func newListCmd(conf *config.Config, versionManager versionmanager.VersionManage } 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 { diff --git a/go.mod b/go.mod index 8524487b..d0ae6c37 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index c646e4e1..3009c9b7 100644 --- a/go.sum +++ b/go.sum @@ -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=