blob: a2996516ec0bad4e875b1ff2c6256b96df78f5d0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package compose
import (
"fmt"
"git.sr.ht/~rjarry/aerc/app"
)
type Detach struct {
Path string `opt:"path" required:"false"`
}
func init() {
register(Detach{})
}
func (Detach) Aliases() []string {
return []string{"detach"}
}
func (Detach) Complete(args []string) []string {
composer, _ := app.SelectedTabContent().(*app.Composer)
return composer.GetAttachments()
}
func (d Detach) Execute(args []string) error {
composer, _ := app.SelectedTabContent().(*app.Composer)
if d.Path == "" {
// if no attachment is specified, delete the first in the list
atts := composer.GetAttachments()
if len(atts) > 0 {
d.Path = atts[0]
} else {
return fmt.Errorf("No attachments to delete")
}
}
if err := composer.DeleteAttachment(d.Path); err != nil {
return err
}
app.PushSuccess(fmt.Sprintf("Detached %s", d.Path))
return nil
}
|