fix: review findings for lazysecrets list: recent means the last 90 days, cache saves lock and keep deletions and the TUI's cursors, failed lists aren't retried, one expiry rule
CI / Checks (pull_request) Successful in 40s
PR title / Conventional title (pull_request) Successful in 2s

This commit is contained in:
keb committed 2026-10-14 21:24:01 +02:00
1 parent ea58530068
commit db4d64012d
23 files changed
+333 -107

No files matched your search

+21 -21
View File
@@ -18,6 +18,7 @@ import (
"charm.land/lipgloss/v2"
"git.kebcloud.no/keb/lazysecrets/internal/cachefile"
"git.kebcloud.no/keb/lazysecrets/internal/expiry"
"git.kebcloud.no/keb/lazysecrets/internal/listing"
"git.kebcloud.no/keb/lazysecrets/internal/provider"
"git.kebcloud.no/keb/lazysecrets/internal/store"
@@ -127,20 +128,18 @@ func listCmd(providers []provider.Provider, st *store.Store, cachePath string, t
if cachePath != "" {
f = cachefile.Read(cachePath)
}
f = listing.Run(context.Background(), listing.Options{
f, loaded := listing.Run(context.Background(), listing.Options{
Providers: providers, Cache: f, MaxAge: *maxAge, Cached: *cached, Kinds: only, Timeout: timeout,
Mark: func(link, account string) (bool, time.Time, int, string) {
Mark: func(link, account string) listing.Marks {
n := st.Node(link)
return n.StarredFor(account), n.LastUsed, n.Uses, n.Note
return listing.Marks{Starred: n.StarredFor(account), Recent: n.UsedLately(now),
LastUsed: n.LastUsed, Uses: n.Uses, Note: n.Note}
},
}, emit)
if cachePath != "" && !*cached {
byID := map[string]provider.Provider{}
for _, p := range providers {
byID[p.ID()] = p
}
keep := func(id string) bool { p, ok := byID[id]; return ok && p.Kind() != provider.KindRepo }
if err := cachefile.Save(cachePath, f, keep, time.Now()); err != nil {
// Only what was loaded: list never moves a cursor, so the TUI's stay.
if cachePath != "" && loaded {
f.Cursor = nil
if err := cachefile.Save(cachePath, f, cachefile.Keep(providers), time.Now()); err != nil {
return err
}
}
@@ -170,16 +169,13 @@ func noteOf(e listing.Entry, theme styles.Styles, iconSet icons.Set, icon, color
// is "". Its mark (✗, ⚠) is before the name.
func expiryOf(e listing.Entry, theme styles.Styles, warn time.Duration, now time.Time, color bool) string {
render := renderer(color)
left := e.Expires.Sub(now)
switch {
case e.Expires.IsZero() || left > warn:
return ""
case left <= 0:
switch state, left := expiry.Of(e.Expires, now, warn); state {
case expiry.Expired:
return render(theme.Error, "expired")
case left < 24*time.Hour:
return render(theme.Warning, fmt.Sprintf("expires in %dh", max(1, int(left.Hours()))))
case expiry.Soon:
return render(theme.Warning, "expires in "+expiry.Left(left))
}
return render(theme.Warning, fmt.Sprintf("expires in %dd", int(left.Hours()/24)))
return ""
}
// errorOf is why a list couldn't be read, in red, or "". Its mark (✗)
@@ -230,10 +226,14 @@ func (m marks) of(e listing.Entry) string {
}
}
// What's wrong, then what to watch: room for one of them.
switch left := e.Expires.Sub(m.now); {
case e.Error != "" || (m.expiry && !e.Expires.IsZero() && left <= 0):
state := expiry.None
if m.expiry {
state, _ = expiry.Of(e.Expires, m.now, m.warn)
}
switch {
case e.Error != "" || state == expiry.Expired:
mark(true, m.theme.Error, "✗")
case m.expiry && !e.Expires.IsZero() && left <= m.warn:
case state == expiry.Soon:
mark(true, m.theme.Warning, "⚠")
default:
mark(false, m.theme.Error, "")