aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-11-24 16:03:03 +0100
committerRobin Jarry <robin@jarry.cc>2023-12-30 15:42:09 +0100
commitcf47763e5582563f712b4a40a9b299378aba9003 (patch)
treeaf83b863a644a90a69eef891a4ce06023224a213 /lib
parentfdd9f7991aa50bd99d21c178a2816fc075eead6b (diff)
downloadaerc-cf47763e5582563f712b4a40a9b299378aba9003.tar.gz
patch/list: add list sub-cmd
Implement the :patch list command. List the the current project and add a flag to list all saved projects. Use the pager to display the data and extract the pager commands and move them into the config package. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib')
-rw-r--r--lib/pama/list.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/pama/list.go b/lib/pama/list.go
new file mode 100644
index 00000000..950f130d
--- /dev/null
+++ b/lib/pama/list.go
@@ -0,0 +1,59 @@
+package pama
+
+import (
+ "errors"
+ "io"
+ "strings"
+
+ "git.sr.ht/~rjarry/aerc/lib/pama/models"
+ "git.sr.ht/~rjarry/aerc/log"
+)
+
+func (m PatchManager) Projects(name string) ([]models.Project, error) {
+ all, err := m.store().Projects()
+ if err != nil {
+ return nil, storeErr(err)
+ }
+ if len(name) == 0 {
+ return all, nil
+ }
+ var projects []models.Project
+ for _, p := range all {
+ if strings.Contains(p.Name, name) {
+ projects = append(projects, p)
+ }
+ }
+ if len(projects) == 0 {
+ return nil, errors.New("No projects found.")
+ }
+ return projects, nil
+}
+
+func (m PatchManager) NewReader(projects []models.Project) io.Reader {
+ cur, err := m.CurrentProject()
+ currentName := cur.Name
+ if err != nil {
+ log.Warnf("could not get current project: %v", err)
+ currentName = ""
+ }
+
+ readers := make([]io.Reader, 0, len(projects))
+ for _, p := range projects {
+ rc, err := m.rc(p.RevctrlID, p.Root)
+ if err != nil {
+ log.Errorf("project '%s' failed with: %v", p.Name, err)
+ continue
+ }
+
+ notes := make(map[string]string)
+ for _, c := range p.Commits {
+ if !rc.Exists(c.ID) {
+ notes[c.ID] = "Rebase needed"
+ }
+ }
+
+ active := p.Name == currentName && len(projects) > 1
+ readers = append(readers, p.NewReader(active, notes))
+ }
+ return io.MultiReader(readers...)
+}