Debian Codegraph @

commands/patch/drop.go

raw
1 package patch
2
3 import (
4 "fmt"
5 "time"
6
7 "git.sr.ht/~rjarry/aerc/app"
8 "git.sr.ht/~rjarry/aerc/commands"
9 "git.sr.ht/~rjarry/aerc/lib/log"
10 "git.sr.ht/~rjarry/aerc/lib/pama"
11 )
12
13 type Drop struct {
14 Tag string `opt:"tag" complete:"CompleteTag" desc:"Repository patch tag."`
15 }
16
17 func init() {
18 register(Drop{})
19 }
20
21 func (Drop) Description() string {
22 return "Drop a patch from the repository."
23 }
24
25 func (Drop) Context() commands.CommandContext {
26 return commands.GLOBAL
27 }
28
29 func (Drop) Aliases() []string {
30 return []string{"drop"}
31 }
32
33 func (*Drop) CompleteTag(arg string) []string {
34 patches, err := pama.New().CurrentPatches()
35 if err != nil {
36 log.Errorf("failed to get current patches: %v", err)
37 return nil
38 }
39 return commands.FilterList(patches, arg, nil)
40 }
41
42 func (r Drop) Execute(args []string) error {
43 patch := r.Tag
44 err := pama.New().DropPatch(patch)
45 if err != nil {
46 return err
47 }
48 app.PushStatus(fmt.Sprintf("Patch %s has been dropped", patch),
49 10*time.Second)
50 return nil
51 }