aboutsummaryrefslogtreecommitdiffstats
path: root/commands/patch/drop.go
blob: a888568a5c2ab00d8ed5e877d243293cbad36a30 (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
47
package patch

import (
	"fmt"
	"time"

	"git.sr.ht/~rjarry/aerc/app"
	"git.sr.ht/~rjarry/aerc/commands"
	"git.sr.ht/~rjarry/aerc/lib/log"
	"git.sr.ht/~rjarry/aerc/lib/pama"
)

type Drop struct {
	Tag string `opt:"tag" complete:"CompleteTag"`
}

func init() {
	register(Drop{})
}

func (Drop) Context() commands.CommandContext {
	return commands.GLOBAL
}

func (Drop) Aliases() []string {
	return []string{"drop"}
}

func (*Drop) CompleteTag(arg string) []string {
	patches, err := pama.New().CurrentPatches()
	if err != nil {
		log.Errorf("failed to get current patches: %v", err)
		return nil
	}
	return commands.FilterList(patches, arg, nil)
}

func (r Drop) Execute(args []string) error {
	patch := r.Tag
	err := pama.New().DropPatch(patch)
	if err != nil {
		return err
	}
	app.PushStatus(fmt.Sprintf("Patch %s has been dropped", patch),
		10*time.Second)
	return nil
}