feat: lazysecrets list prints everything lazysecrets can find, for fzf and editor pickers (#70)
`lazysecrets list` prints every source, vault and secret lazysecrets can find, one per line, for fzf, editor pickers and scripts: what Go to searches, without the TUI. What's cached prints at once; what's missing or older than `--max-age` loads in the background and streams in. It stops when the reader goes (a pick in fzf), saving what it loaded. - Text: kind, mark (✗/⚠, ★, ◷ and the provider icon), name, status (why it couldn't be read, or expired / expires in 12d), note, account and link, tab-separated; kind first and account and link last, so new fields go between. Coloured from the theme; `--color never`, `--icons=false`, `--stars=false`, `--recent`, `--notes=false`, `--expiry=false`. - `--format json`: an object per line, with starred, recent, lastUsed and uses, expires, enabled, note, reference and url too. - `--kind` lists only some kinds, and doesn't load lists only other kinds need; `--cached` loads nothing. - `lazysecrets open --action go|copy|show` skips the "what to do" menu and ends in the list, like Go to; `open` and `get` take `--account`, the account list printed, rather than asking which. - The cache file moved to `internal/cachefile`: saves merge with the file under a lock, so list and the TUI don't undo each other. - `ui.recentIcon` marks items used lately with ◷ in the TUI's lists too; Recent now means the last 90 days. - --demo has stars, notes, recent use, and expired, expiring and disabled secrets. - docs/integration.md documents get, list and an fzf picker; docs/links.md is docs/sharing.md. Reviewed-on: #70 Co-authored-by: Karl-Einar Bergstrøm <karl-einarb@outlook.com>
This commit was merged in pull request #70.
This commit is contained in:
1 parent
dbb0eb2bbd
commit
39454d47a8
45 files changed
+2107
-222
No files matched your search
@@ -56,9 +56,12 @@ type resolvedMsg struct {
|
||||
act linkAction
|
||||
sourceRow string
|
||||
others []string // other accounts' rows that also found the vault
|
||||
choices []choice // several candidates: ask
|
||||
linked *provider.Container
|
||||
err error
|
||||
// find ends in the list, like Go to, not on the details: opened by a
|
||||
// tool that found it (lazysecrets open --action, from fzf).
|
||||
find bool
|
||||
choices []choice // several candidates: ask
|
||||
linked *provider.Container
|
||||
err error
|
||||
}
|
||||
|
||||
type choice struct {
|
||||
@@ -218,6 +221,9 @@ func (m *Model) openSource(r ref.Ref) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if row, ok := preferredRow(r, choices); ok {
|
||||
choices = []choice{{sourceRow: row}}
|
||||
}
|
||||
switch len(choices) {
|
||||
case 0:
|
||||
m.flash = flash{text: "open: " + describeRef(r) + " isn't in your sources", isErr: true}
|
||||
@@ -404,18 +410,59 @@ func (m *Model) handleResolved(msg resolvedMsg) {
|
||||
for i := range msg.choices {
|
||||
msg.choices[i].label = "Open in " + msg.choices[i].label
|
||||
}
|
||||
m.chooseSource("Scope "+msg.ref.Scope+" is in several workspaces", msg.ref, msg.act, msg.choices, true)
|
||||
m.chooseSource("Scope "+msg.ref.Scope+" is in several workspaces", msg.ref, msg.act, msg.choices, !msg.find)
|
||||
case len(msg.others) > 0:
|
||||
var choices []choice
|
||||
for _, row := range append([]string{msg.sourceRow}, msg.others...) {
|
||||
choices = append(choices, choice{label: "Open with " + m.sourceLabel(row), sourceRow: row})
|
||||
}
|
||||
m.chooseSource("Several accounts can see "+msg.ref.ContainerName(), msg.ref, msg.act, choices, true)
|
||||
if row, ok := preferredRow(msg.ref, choices); ok {
|
||||
m.navResolved(msg, row)
|
||||
return
|
||||
}
|
||||
m.chooseSource("Several accounts can see "+msg.ref.ContainerName(), msg.ref, msg.act, choices, !msg.find)
|
||||
case msg.linked != nil:
|
||||
m.addLinked(*msg.linked)
|
||||
m.startLinkNav(msg.ref, msg.act, linksRowID)
|
||||
m.navResolved(msg, linksRowID)
|
||||
default:
|
||||
m.startLinkNav(msg.ref, msg.act, msg.sourceRow)
|
||||
m.navResolved(msg, msg.sourceRow)
|
||||
}
|
||||
}
|
||||
|
||||
// preferredRow is the choice under the account the reference asks for
|
||||
// (ref.Ref.Account), if it's one of them.
|
||||
func preferredRow(r ref.Ref, choices []choice) (string, bool) {
|
||||
for _, c := range choices {
|
||||
if r.Account != "" && providerOf(c.sourceRow) == r.Account {
|
||||
return c.sourceRow, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// navResolved goes to what a resolved link points at, under row.
|
||||
func (m *Model) navResolved(msg resolvedMsg, row string) {
|
||||
if msg.find {
|
||||
m.startNav(msg.ref, msg.act, row)
|
||||
return
|
||||
}
|
||||
m.startLinkNav(msg.ref, msg.act, row)
|
||||
}
|
||||
|
||||
// findRef is openRef ending in the list, like Go to: for a link a tool
|
||||
// found (lazysecrets open --action).
|
||||
func (m *Model) findRef(r ref.Ref, act linkAction) tea.Cmd {
|
||||
cmd := m.openRef(r, act)
|
||||
if cmd == nil {
|
||||
return nil
|
||||
}
|
||||
return func() tea.Msg {
|
||||
msg := cmd()
|
||||
if rm, ok := msg.(resolvedMsg); ok {
|
||||
rm.find = true
|
||||
return rm
|
||||
}
|
||||
return msg
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user