1
0
Fork 0
mirror of https://git.sr.ht/~rjarry/aerc synced 2025-07-13 04:30:22 +02:00
aerc/commands/patch/drop.go
Robin Jarry d0484b153a completion: add command option descriptions
Add `desc:""` struct field tags in all command arguments where it makes
sense.

The description values will be returned along with completion choices.

Implements: https://todo.sr.ht/~rjarry/aerc/271
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bojan Gabric <bojan@bojangabric.com>
Tested-by: Jason Cox <me@jasoncarloscox.com>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
2024-10-23 10:22:51 +02:00

51 lines
986 B
Go

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" desc:"Repository patch tag."`
}
func init() {
register(Drop{})
}
func (Drop) Description() string {
return "Drop a patch from the repository."
}
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
}