fix: lazysecrets list keeps the provider icon on error lines

This commit is contained in:
keb committed 2026-10-14 21:24:01 +02:00
1 parent 24b38d7321
commit 3734989b15
3 files changed
+9 -13

No files matched your search

+4 -8
View File
@@ -34,7 +34,7 @@ import (
//
// What's cached prints at once; what's missing or older than --max-age
// follows as it loads. A list that can't be read is a line too, as it
// fails: ✗, the vault or source, and why, in the theme's error colour.
// fails: the vault or source, then ✗ and why in the theme's error colour.
// They're in the output rather than on stderr, which would draw over fzf.
func listCmd(providers []provider.Provider, cachePath string, timeout func(provider.Kind) time.Duration, theme styles.Styles, withIcons bool, args []string, out io.Writer) error {
fs := flag.NewFlagSet("list", flag.ContinueOnError)
@@ -126,7 +126,7 @@ var oneLine = strings.NewReplacer("\t", " ", "\r\n", " ", "\n", " ", "\r", " ")
// nameOf is an entry's name for the text format: the provider's icon,
// the path with the item's own name standing out, and the account. A
// list that couldn't be read has ✗ for the icon, and why after it.
// list that couldn't be read has ✗ and why after it.
func nameOf(e listing.Entry, theme styles.Styles, iconSet icons.Set, color bool) string {
render := func(st lipgloss.Style, s string) string {
if !color || s == "" {
@@ -141,10 +141,6 @@ func nameOf(e listing.Entry, theme styles.Styles, iconSet icons.Set, color bool)
}
}
icon := iconSet.Prefix(kind)
iconStyle := theme.Kind(kind)
if e.Error != "" {
icon, iconStyle = "✗ ", theme.Error
}
var name string
if n := len(e.Path); n > 0 {
if n > 1 {
@@ -156,7 +152,7 @@ func nameOf(e listing.Entry, theme styles.Styles, iconSet icons.Set, color bool)
name += render(theme.Muted, " · "+e.Account)
}
if e.Error != "" {
name += " " + render(theme.Error, e.Error)
name += " " + render(theme.Error, "✗ "+e.Error)
}
return render(iconStyle, strings.TrimSuffix(icon, " ")) + strings.Repeat(" ", min(len(icon), 1)) + name
return render(theme.Kind(kind), strings.TrimSuffix(icon, " ")) + strings.Repeat(" ", min(len(icon), 1)) + name
}
+2 -2
View File
@@ -26,10 +26,10 @@ func TestListNames(t *testing.T) {
func TestListErrorNames(t *testing.T) {
e := listing.Entry{Provider: "azure", Path: []string{"platform-prod", "kv-restricted"}, Error: "403 Forbidden"}
if got := nameOf(e, styles.Default(), icons.NerdFont, false); got != "✗ platform-prod / kv-restricted 403 Forbidden" {
if got := nameOf(e, styles.Default(), icons.NerdFont, false); got != icons.NerdFont.Azure+" platform-prod / kv-restricted ✗ 403 Forbidden" {
t.Errorf("plain: %q", got)
}
red := styles.Default().Error.Render("403 Forbidden")
red := styles.Default().Error.Render("✗ 403 Forbidden")
if got := nameOf(e, styles.Default(), icons.NerdFont, true); !strings.HasSuffix(got, red) {
t.Errorf("why isn't in the error colour: %q", got)
}