Skip to content

Commit

Permalink
display last use in list #181
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 d5ef9fa commit a0c3401
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
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, ")"))

Check failure on line 215 in cmd/tenv/subcmd.go

View workflow job for this annotation

GitHub Actions / lint

undefined: time.DateOnly (typecheck)
}
case noUseDate:
loghelper.StdDisplay(loghelper.Concat(" ", version, " (never used)"))
default:
loghelper.StdDisplay(loghelper.Concat(" ", version, " (used ", useDate.Format(time.DateOnly), ")"))

Check failure on line 220 in cmd/tenv/subcmd.go

View workflow job for this annotation

GitHub Actions / lint

undefined: time.DateOnly (typecheck)
}
}
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

0 comments on commit a0c3401

Please sign in to comment.