feat: lazysecrets list merges error and expiry into one status field

This commit is contained in:
keb committed 2026-10-14 21:24:01 +02:00
1 parent 37164158ca
commit 2c9c37f809
1 file changed
+11 -11
+11 -11
View File
@@ -29,10 +29,9 @@ import (
// //
// lazysecrets list | fzf --ansi --delimiter='\t' --with-nth='2..-3' --nth='2..' --accept-nth=-1 // lazysecrets list | fzf --ansi --delimiter='\t' --with-nth='2..-3' --nth='2..' --accept-nth=-1
// //
// Each line is the kind, a mark (★, ◷ and the provider's icon), the name, // Each line is the kind, a mark (✗ or ⚠, ★, ◷ and the provider's icon),
// why it couldn't be read (empty unless it failed), whether it expires // the name, a status (why it couldn't be read, or that it has expired or
// soon or has expired (empty unless so), the account and the link, // expires soon; else empty), the account and the link, tab-separated. The mark has a field of its own so a search can
// tab-separated. The mark has a field of its own so a search can
// leave it out (fzf --nth), and ^prod finds names starting with prod. The // leave it out (fzf --nth), and ^prod finds names starting with prod. The
// name is coloured from the theme, // name is coloured from the theme,
// with the provider's icon (as in the TUI: --icons, LAZYSECRETS_ICONS, // with the provider's icon (as in the TUI: --icons, LAZYSECRETS_ICONS,
@@ -46,12 +45,12 @@ func listCmd(providers []provider.Provider, st *store.Store, cachePath string, t
fs := flag.NewFlagSet("list", flag.ContinueOnError) fs := flag.NewFlagSet("list", flag.ContinueOnError)
cached := fs.Bool("cached", false, "only what's cached, and repos: load nothing from Azure or Databricks") cached := fs.Bool("cached", false, "only what's cached, and repos: load nothing from Azure or Databricks")
maxAge := fs.Duration("max-age", 2*time.Minute, "load cached lists older than this again") maxAge := fs.Duration("max-age", 2*time.Minute, "load cached lists older than this again")
format := fs.String("format", "text", "text: kind, mark, name, error, expiry, account and link, tab-separated; json: an object per line") format := fs.String("format", "text", "text: kind, mark, name, status, account and link, tab-separated; json: an object per line")
color := fs.String("color", "always", "colour the names (text): always or never; fzf needs --ansi") color := fs.String("color", "always", "colour the names (text): always or never; fzf needs --ansi")
iconsOn := fs.Bool("icons", withIcons, "put the provider's Nerd Font icon before names (text)") iconsOn := fs.Bool("icons", withIcons, "put the provider's Nerd Font icon before names (text)")
stars := fs.Bool("stars", true, "put ★ before starred names, in the theme's favouriteColor (text)") stars := fs.Bool("stars", true, "put ★ before starred names, in the theme's favouriteColor (text)")
recent := fs.Bool("recent", withRecent, "put ◷ before names used lately, in mutedColor (text; default ui.recentIcon)") recent := fs.Bool("recent", withRecent, "put ◷ before names used lately, in mutedColor (text; default ui.recentIcon)")
expiry := fs.Bool("expiry", true, "say which expire within ui.expiryWarningDays (⚠ 12d) or have expired (✗ expired), after the name (text)") expiry := fs.Bool("expiry", true, "mark and say which have expired (✗ expired) or expire within ui.expiryWarningDays (⚠ expires in 12d) (text)")
kinds := fs.String("kind", "", "only these kinds, comma-separated: "+strings.Join(listing.Kinds, ", ")+" (vault: also scopes and repo files)") kinds := fs.String("kind", "", "only these kinds, comma-separated: "+strings.Join(listing.Kinds, ", ")+" (vault: also scopes and repo files)")
showErrors := fs.Bool("errors", true, "list the lists that can't be read, with why (text: ✗ lines; json: \"error\")") showErrors := fs.Bool("errors", true, "list the lists that can't be read, with why (text: ✗ lines; json: \"error\")")
if err := fs.Parse(args); err != nil { if err := fs.Parse(args); err != nil {
@@ -86,13 +85,14 @@ func listCmd(providers []provider.Provider, st *store.Store, cachePath string, t
colored := *color == "always" colored := *color == "always"
mark := m.of(e) mark := m.of(e)
name := nameOf(e, theme, colored) name := nameOf(e, theme, colored)
why := errorOf(e, theme, colored) // Why it couldn't be read (vaults, sources), or when it
var expires string // expires (secrets, keys, certificates): never both.
if *expiry { status := errorOf(e, theme, colored)
expires = expiryOf(e, theme, expiryWarn, now, colored) if status == "" && *expiry {
status = expiryOf(e, theme, expiryWarn, now, colored)
} }
// A tab or line break in a name would break the line up. // A tab or line break in a name would break the line up.
_, err := fmt.Fprintf(out, "%s\t%s\t%s\t%s\t%s\t%s\t%s\n", e.Kind, mark, oneLine.Replace(name), oneLine.Replace(why), expires, e.Account, e.Link) _, err := fmt.Fprintf(out, "%s\t%s\t%s\t%s\t%s\t%s\n", e.Kind, mark, oneLine.Replace(name), oneLine.Replace(status), e.Account, e.Link)
return err return err
} }
case "json": case "json":