feat: lazysecrets list prints everything lazysecrets can find, for fzf and editor pickers #70
No files matched your search
@@ -34,7 +34,7 @@ import (
|
|||||||
//
|
//
|
||||||
// What's cached prints at once; what's missing or older than --max-age
|
// 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
|
// 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.
|
// 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 {
|
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)
|
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,
|
// 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 ✗ and why after it.
|
||||||
func nameOf(e listing.Entry, theme styles.Styles, iconSet icons.Set, color bool) string {
|
func nameOf(e listing.Entry, theme styles.Styles, iconSet icons.Set, color bool) string {
|
||||||
render := func(st lipgloss.Style, s string) string {
|
render := func(st lipgloss.Style, s string) string {
|
||||||
if !color || s == "" {
|
if !color || s == "" {
|
||||||
@@ -141,10 +141,6 @@ func nameOf(e listing.Entry, theme styles.Styles, iconSet icons.Set, color bool)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
icon := iconSet.Prefix(kind)
|
icon := iconSet.Prefix(kind)
|
||||||
iconStyle := theme.Kind(kind)
|
|
||||||
if e.Error != "" {
|
|
||||||
icon, iconStyle = "✗ ", theme.Error
|
|
||||||
}
|
|
||||||
var name string
|
var name string
|
||||||
if n := len(e.Path); n > 0 {
|
if n := len(e.Path); n > 0 {
|
||||||
if n > 1 {
|
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)
|
name += render(theme.Muted, " · "+e.Account)
|
||||||
}
|
}
|
||||||
if e.Error != "" {
|
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
|
||||||
}
|
}
|
||||||
@@ -26,10 +26,10 @@ func TestListNames(t *testing.T) {
|
|||||||
|
|
||||||
func TestListErrorNames(t *testing.T) {
|
func TestListErrorNames(t *testing.T) {
|
||||||
e := listing.Entry{Provider: "azure", Path: []string{"platform-prod", "kv-restricted"}, Error: "403 Forbidden"}
|
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)
|
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) {
|
if got := nameOf(e, styles.Default(), icons.NerdFont, true); !strings.HasSuffix(got, red) {
|
||||||
t.Errorf("why isn't in the error colour: %q", got)
|
t.Errorf("why isn't in the error colour: %q", got)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -162,9 +162,9 @@ only other kinds need aren't loaded: `--kind source,vault` asks for no
|
|||||||
secrets. Keys and certificates load only when asked for this way; else,
|
secrets. Keys and certificates load only when asked for this way; else,
|
||||||
like Go to, they're listed as far as you opened them in lazysecrets.
|
like Go to, they're listed as far as you opened them in lazysecrets.
|
||||||
|
|
||||||
A vault or source it can't read is a line too, as it fails: `✗`, its
|
A vault or source it can't read is a line too, as it fails: its name,
|
||||||
name and why, in red (`errorColor`), with its link, so opening it shows
|
then `✗` and why in red (`errorColor`), with its link, so opening it
|
||||||
more. They're in the list, not on stderr, which would draw over fzf.
|
shows more. They're in the list, not on stderr, which would draw over fzf.
|
||||||
`--errors=false` leaves them out.
|
`--errors=false` leaves them out.
|
||||||
|
|
||||||
The name is coloured from your [theme](config.md#theme), with the
|
The name is coloured from your [theme](config.md#theme), with the
|
||||||
|
|||||||
Reference in new issue
Block a user