feat: lazysecrets open --action goes, copies or shows without asking
This commit is contained in:
4 files changed
+65
-19
No files matched your search
+23
-7
@@ -133,6 +133,9 @@ type Options struct {
|
||||
NoHistory bool
|
||||
// Open is a reference to open at startup (lazysecrets open <ref>).
|
||||
Open *ref.Ref
|
||||
// OpenAction, if set, is what to do with Open, rather than asking:
|
||||
// go to it, and maybe copy or show its value (OpenActions).
|
||||
OpenAction string
|
||||
// Styles, if set, replaces the default theme (styles.FromTheme), and
|
||||
// DefaultFg the terminal's default text colour.
|
||||
Styles *styles.Styles
|
||||
@@ -283,6 +286,7 @@ type Model struct {
|
||||
prompt *modal // popup that has the keyboard
|
||||
linked []provider.Container // vaults opened from links, this session
|
||||
open *ref.Ref // reference to open at startup
|
||||
openAction string // and what to do with it, or ask
|
||||
|
||||
shareKey string // the config's sharing.key
|
||||
shareRules share.Rules // and sharing.keyRules
|
||||
@@ -447,7 +451,7 @@ func New(providers []provider.Provider, opts Options) Model {
|
||||
}
|
||||
m.defaultFg = opts.DefaultFg
|
||||
m.help = newHelp(m.st)
|
||||
m.open = opts.Open
|
||||
m.open, m.openAction = opts.Open, opts.OpenAction
|
||||
saved := m.store.Layout()
|
||||
m.split, m.heights = saved.Split, saved.Heights
|
||||
|
||||
@@ -521,18 +525,26 @@ func (m Model) Init() tea.Cmd {
|
||||
cmds = append(cmds, m.fetchLatest(false))
|
||||
}
|
||||
if m.open != nil {
|
||||
r := *m.open
|
||||
cmds = append(cmds, func() tea.Msg { return openRefMsg{r} })
|
||||
msg := openRefMsg{ref: *m.open, action: m.openAction}
|
||||
cmds = append(cmds, func() tea.Msg { return msg })
|
||||
}
|
||||
return tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
// openRefMsg starts opening a reference from outside the key handler.
|
||||
type openRefMsg struct{ ref ref.Ref }
|
||||
// openRefMsg starts opening a reference from outside the key handler:
|
||||
// asking what to do with it, or doing action (OpenActions).
|
||||
type openRefMsg struct {
|
||||
ref ref.Ref
|
||||
action string
|
||||
}
|
||||
|
||||
// OpenActions are what lazysecrets open --action takes, the Open link
|
||||
// menu's choices that go there.
|
||||
var OpenActions = map[string]linkAction{"go": actGo, "copy": actCopy, "show": actShow}
|
||||
|
||||
// OpenLink is a message offering r in the Open link popup, for links
|
||||
// handed over by the link handler (Program.Send).
|
||||
func OpenLink(r ref.Ref) tea.Msg { return openRefMsg{r} }
|
||||
func OpenLink(r ref.Ref) tea.Msg { return openRefMsg{ref: r} }
|
||||
|
||||
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
var cmds []tea.Cmd
|
||||
@@ -589,7 +601,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
|
||||
case openRefMsg:
|
||||
m.deferHandlerSetup() // the link first
|
||||
cmds = append(cmds, m.offerRef("Open link", msg.ref, false))
|
||||
if act, ok := OpenActions[msg.action]; ok && !msg.ref.IsShare() {
|
||||
cmds = append(cmds, m.openRef(msg.ref, act))
|
||||
} else {
|
||||
cmds = append(cmds, m.offerRef("Open link", msg.ref, false))
|
||||
}
|
||||
|
||||
case resolvedMsg:
|
||||
m.handleResolved(msg)
|
||||
|
||||
Reference in new issue
Block a user