summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.go17
-rw-r--r--human.go25
-rw-r--r--scanIterator.go19
3 files changed, 43 insertions, 18 deletions
diff --git a/common.go b/common.go
index 2dc38ef..42a0c30 100644
--- a/common.go
+++ b/common.go
@@ -5,10 +5,8 @@ import (
"os"
"path/filepath"
"sort"
- "time"
"go.wit.com/gui"
- "go.wit.com/lib/gui/shell"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/log"
)
@@ -226,18 +224,3 @@ func (rl *RepoList) MakeGoWork() error {
fmt.Fprintln(f, ")")
return nil
}
-
-// makes a human readable thing for standard out.
-func (r *RepoRow) StandardHeader() string {
- lastTag := r.LastTag()
- tag := r.Status.NewestTag()
- gitAge, _ := tag.GetDate()
- dur := time.Since(gitAge)
-
- master := r.Status.GetMasterVersion()
- devel := r.Status.GetDevelVersion()
- user := r.Status.GetUserVersion()
-
- header := fmt.Sprintf("%-35s %5s %-10s %-10s %-10s %-10s %-15s", r.Name(), shell.FormatDuration(dur), lastTag, master, devel, user, r.State())
- return header
-}
diff --git a/human.go b/human.go
new file mode 100644
index 0000000..0c22ae8
--- /dev/null
+++ b/human.go
@@ -0,0 +1,25 @@
+package repolist
+
+// make human readable output
+
+import (
+ "fmt"
+ "time"
+
+ "go.wit.com/lib/gui/shell"
+)
+
+// makes a human readable thing for standard out.
+func (r *RepoRow) StandardHeader() string {
+ lastTag := r.LastTag()
+ tag := r.Status.NewestTag()
+ gitAge, _ := tag.GetDate()
+ dur := time.Since(gitAge)
+
+ master := r.Status.GetMasterVersion()
+ devel := r.Status.GetDevelVersion()
+ user := r.Status.GetUserVersion()
+
+ header := fmt.Sprintf("%-35s %5s %-10s %-10s %-10s %-10s %-15s", r.Name(), shell.FormatDuration(dur), lastTag, master, devel, user, r.State())
+ return header
+}
diff --git a/scanIterator.go b/scanIterator.go
index 4214014..7f347b2 100644
--- a/scanIterator.go
+++ b/scanIterator.go
@@ -3,6 +3,7 @@ package repolist
import (
"fmt"
"os"
+ "sort"
)
type RepoIterator struct {
@@ -52,6 +53,22 @@ func (r *RepoList) ReposAll() *RepoIterator {
return iterator
}
+func (r *RepoList) ReposSortByName() *RepoIterator {
+ repoPointers := r.selectRepoAll()
+
+ sort.Sort(ByName(repoPointers))
+
+ iterator := NewRepoIterator(repoPointers)
+
+ return iterator
+}
+
+type ByName []*RepoRow
+
+func (a ByName) Len() int { return len(a) }
+func (a ByName) Less(i, j int) bool { return a[i].GoPath() < a[j].GoPath() }
+func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
+
// SelectRepoPointers safely returns a slice of pointers to Repo records.
func (r *RepoList) selectRepoAll() []*RepoRow {
r.RLock()
@@ -67,7 +84,7 @@ func (r *RepoList) selectRepoAll() []*RepoRow {
if repo.Status == nil {
continue
}
- if ! repo.Status.InitOk {
+ if !repo.Status.InitOk {
continue
}
repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration