blob: 4847713f86e0539c8c95d7e08ef0c099b5e1b9e4 (
plain) (
tree)
|
|
package compose
import (
"fmt"
"strings"
"git.sr.ht/~rjarry/aerc/app"
)
type Detach struct{}
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 (Detach) Execute(args []string) error {
var path string
composer, _ := app.SelectedTabContent().(*app.Composer)
if len(args) > 1 {
path = strings.Join(args[1:], " ")
} else {
// if no attachment is specified, delete the first in the list
atts := composer.GetAttachments()
if len(atts) > 0 {
path = atts[0]
} else {
return fmt.Errorf("No attachments to delete")
}
}
if err := composer.DeleteAttachment(path); err != nil {
return err
}
app.PushSuccess(fmt.Sprintf("Detached %s", path))
return nil
}
|