aboutsummaryrefslogtreecommitdiffstats
path: root/commands/patch/remove.go
blob: 6697177bcbcf04a2756d8eb0759bdb97f4789582 (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
package patch

import (
	"fmt"
	"time"

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

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

func init() {
	register(Remove{})
}

func (Remove) Aliases() []string {
	return []string{"remove"}
}

func (*Remove) 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 Remove) Execute(args []string) error {
	patch := r.Tag
	err := pama.New().RemovePatch(patch)
	if err != nil {
		return err
	}
	app.PushStatus(fmt.Sprintf("Patch %s has been removed", patch),
		10*time.Second)
	return nil
}