diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-27 18:12:28 +0100 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2021-02-27 18:12:28 +0100 |
commit | 2ab1946a8b19b6b20abb38d79c021ca6be8bfb40 (patch) | |
tree | 6937f6612928ba69d967dcfa6849a8613a4ee48d | |
parent | ebb116894852676d3779159dedea1ac648d11b35 (diff) | |
download | feed2imap-go-2ab1946a8b19b6b20abb38d79c021ca6be8bfb40.tar.gz feed2imap-go-2ab1946a8b19b6b20abb38d79c021ca6be8bfb40.tar.bz2 feed2imap-go-2ab1946a8b19b6b20abb38d79c021ca6be8bfb40.zip |
Improve output of `print-cache`
Diffstat (limited to '')
-rw-r--r-- | internal/feed/cache/cache_v1.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/internal/feed/cache/cache_v1.go b/internal/feed/cache/cache_v1.go index 439846f..f7392e5 100644 --- a/internal/feed/cache/cache_v1.go +++ b/internal/feed/cache/cache_v1.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/hex" "fmt" + "sort" "strconv" "strings" "time" @@ -111,9 +112,22 @@ func (cache *v1Cache) Version() Version { } func (cache *v1Cache) Info() string { + descriptors := make([]feed.Descriptor, len(cache.Ids)) + i := 0 + for descr := range cache.Ids { + descriptors[i] = descr + i++ + } + + sort.Slice(descriptors, func(i, j int) bool { + return descriptors[i].Name < descriptors[j].Name + }) + b := strings.Builder{} - for descr, id := range cache.Ids { - b.WriteString(fmt.Sprintf("%3s: %s (%s)\n", id.String(), descr.Name, descr.Url)) + for _, descr := range descriptors { + id := cache.Ids[descr] + feed := cache.Feeds[id] + b.WriteString(fmt.Sprintf("%3s: %s (%s) (%d items)\n", id.String(), descr.Name, descr.Url, len(feed.Items))) } return b.String() } |