feat: lazysecrets list prints everything lazysecrets can find, for fzf and editor pickers #70

Merged
keb merged 45 commits from feat/list into main 2026-10-14 21:30:44 +02:00
3 changed files with 29 additions and 2 deletions
Showing only changes of commit 24b38d7321 - Show all commits

No files matched your search

+4 -1
View File
@@ -72,7 +72,8 @@ func listCmd(providers []provider.Provider, cachePath string, timeout func(provi
switch *format { switch *format {
case "text": case "text":
write = func(e listing.Entry) error { write = func(e listing.Entry) error {
_, err := fmt.Fprintf(out, "%s\t%s\n", nameOf(e, theme, iconSet, *color == "always"), e.Link) // A tab or line break in a name would break the line up.
_, err := fmt.Fprintf(out, "%s\t%s\n", oneLine.Replace(nameOf(e, theme, iconSet, *color == "always")), e.Link)
return err return err
} }
case "json": case "json":
@@ -121,6 +122,8 @@ func listCmd(providers []provider.Provider, cachePath string, timeout func(provi
return nil // or the reader has what it wanted return nil // or the reader has what it wanted
} }
var oneLine = strings.NewReplacer("\t", " ", "\r\n", " ", "\n", " ", "\r", " ")
// nameOf is an entry's name for the text format: the provider's icon, // 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 // 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 ✗ for the icon, and why after it.
+13 -1
View File
@@ -312,10 +312,22 @@ func (r result) failed() Entry {
default: default:
e = Entry{Kind: "source", Provider: kindOf(r.p.Kind()), Path: []string{r.p.Label()}} e = Entry{Kind: "source", Provider: kindOf(r.p.Kind()), Path: []string{r.p.Label()}}
} }
e.Error = r.err.Error() e.Error = firstLine(r.err.Error())
return e return e
} }
// firstLine is an error's first line, the summary (Azure's go on with
// the caller's IDs and more): an entry is one line. Tabs, which would
// split it into columns, are spaces.
func firstLine(s string) string {
for line := range strings.Lines(s) {
if line = strings.TrimSpace(line); line != "" {
return strings.ReplaceAll(line, "\t", " ")
}
}
return "unreadable"
}
func kindOf(k provider.Kind) string { return strings.ToLower(string(k)) } func kindOf(k provider.Kind) string { return strings.ToLower(string(k)) }
// accountOf is the account part of a source's provider label ("alice" in // accountOf is the account part of a source's provider label ("alice" in
+12
View File
@@ -211,3 +211,15 @@ func TestListKinds(t *testing.T) {
t.Error("a list that failed wasn't listed") t.Error("a list that failed wasn't listed")
} }
} }
func TestErrorsAreOneLine(t *testing.T) {
for in, want := range map[string]string{
"403 Forbidden: Caller is not authorized\nCaller: appid=x;oid=y\nVault: kv;location=z": "403 Forbidden: Caller is not authorized",
"\n timeout\tafter 30s\n": "timeout after 30s",
"": "unreadable",
} {
if got := firstLine(in); got != want {
t.Errorf("firstLine(%q) = %q, want %q", in, got, want)
}
}
}