aboutsummaryrefslogtreecommitdiffstats
path: root/commands/patch/unlink.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/patch/unlink.go')
-rw-r--r--commands/patch/unlink.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/commands/patch/unlink.go b/commands/patch/unlink.go
new file mode 100644
index 00000000..4a78281e
--- /dev/null
+++ b/commands/patch/unlink.go
@@ -0,0 +1,58 @@
+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 Unlink struct {
+ Tag string `opt:"tag" required:"false" complete:"Complete"`
+}
+
+func init() {
+ register(Unlink{})
+}
+
+func (Unlink) Context() commands.CommandContext {
+ return commands.GLOBAL
+}
+
+func (Unlink) Aliases() []string {
+ return []string{"unlink"}
+}
+
+func (*Unlink) Complete(arg string) []string {
+ names, err := pama.New().Names()
+ if err != nil {
+ log.Errorf("failed to get completion: %v", err)
+ return nil
+ }
+ return commands.FilterList(names, arg, nil)
+}
+
+func (d Unlink) Execute(args []string) error {
+ m := pama.New()
+
+ name := d.Tag
+ if name == "" {
+ p, err := m.CurrentProject()
+ if err != nil {
+ return err
+ }
+ name = p.Name
+ }
+
+ err := m.Unlink(name)
+ if err != nil {
+ return err
+ }
+
+ app.PushStatus(fmt.Sprintf("Project '%s' unlinked.", name),
+ 10*time.Second)
+ return nil
+}