aboutsummaryrefslogtreecommitdiffstats
path: root/lib/pama
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-24 16:03:08 +0100
committerRobin Jarry <robin@jarry.cc>2023-12-30 15:42:09 +0100
commit8671d9dc483acf3c69022a8f2915166b83186559 (patch)
tree0a45e5f9b4f5335d150aba110a4a7cf7717ef5b1 /lib/pama
parentd49ed00df00b9d745a385a7b3f67832ce147380d (diff)
downloadaerc-8671d9dc483acf3c69022a8f2915166b83186559.tar.gz
patch/delete: add delete sub-cmd
Implement the :patch delete command. Remove the project data from the permanent store. If no argument is provided, the current project will be deleted. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/pama')
-rw-r--r--lib/pama/delete.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/pama/delete.go b/lib/pama/delete.go
new file mode 100644
index 00000000..18a93a27
--- /dev/null
+++ b/lib/pama/delete.go
@@ -0,0 +1,45 @@
+package pama
+
+import "fmt"
+
+// Delete removes provided project
+func (m PatchManager) Delete(name string) error {
+ store := m.store()
+ names, err := m.Names()
+ if err != nil {
+ return err
+ }
+
+ index := -1
+ for i, s := range names {
+ if s == name {
+ index = i
+ break
+ }
+ }
+ if index < 0 {
+ return fmt.Errorf("Project '%s' not found", name)
+ }
+
+ cur, err := m.CurrentProject()
+ if err == nil && cur.Name == name {
+ var next string
+ for _, s := range names {
+ if name != s {
+ next = s
+ break
+ }
+ }
+ err = store.SetCurrent(next)
+ if err != nil {
+ return storeErr(err)
+ }
+ }
+
+ return storeErr(m.store().DeleteProject(name))
+}
+
+func (m PatchManager) Names() ([]string, error) {
+ names, err := m.store().Names()
+ return names, storeErr(err)
+}