diff options
Diffstat (limited to 'commands/compose/detach.go')
-rw-r--r-- | commands/compose/detach.go | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/commands/compose/detach.go b/commands/compose/detach.go index 487bf225..3b5a6833 100644 --- a/commands/compose/detach.go +++ b/commands/compose/detach.go @@ -2,12 +2,13 @@ package compose import ( "fmt" - "strings" "git.sr.ht/~rjarry/aerc/widgets" ) -type Detach struct{} +type Detach struct { + Path string `opt:"PATH" required:"false"` +} func init() { register(Detach{}) @@ -22,27 +23,24 @@ func (Detach) Complete(aerc *widgets.Aerc, args []string) []string { return composer.GetAttachments() } -func (Detach) Execute(aerc *widgets.Aerc, args []string) error { - var path string +func (d Detach) Execute(aerc *widgets.Aerc, args []string) error { composer, _ := aerc.SelectedTabContent().(*widgets.Composer) - if len(args) > 1 { - path = strings.Join(args[1:], " ") - } else { + if d.Path == "" { // if no attachment is specified, delete the first in the list atts := composer.GetAttachments() if len(atts) > 0 { - path = atts[0] + d.Path = atts[0] } else { return fmt.Errorf("No attachments to delete") } } - if err := composer.DeleteAttachment(path); err != nil { + if err := composer.DeleteAttachment(d.Path); err != nil { return err } - aerc.PushSuccess(fmt.Sprintf("Detached %s", path)) + aerc.PushSuccess(fmt.Sprintf("Detached %s", d.Path)) return nil } |