From 1e4562e9991df974a959774d3a919ed190a4351b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 15 Jul 2018 01:43:20 +0200 Subject: [PATCH] ls: better output --- bug/snapshot.go | 18 ++++++++++++++++++ commands/ls.go | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bug/snapshot.go b/bug/snapshot.go index 8828c33713cd979174eca4fdc27438f6e10d393f..9b9acf873e16a6ee5041181d5ba9ce361ecb65f6 100644 --- a/bug/snapshot.go +++ b/bug/snapshot.go @@ -1,8 +1,26 @@ package bug +import ( + "fmt" + "time" +) + // Snapshot is a compiled form of the Bug data structure used for storage and merge type Snapshot struct { Title string Comments []Comment Labels []Label } + +func (snap Snapshot) Summary() string { + return fmt.Sprintf("c:%d l:%d %s", + len(snap.Comments)-1, + len(snap.Labels), + snap.LastEdit().Format(time.RFC822), + ) +} + +func (snap Snapshot) LastEdit() time.Time { + lastEditTimestamp := snap.Comments[len(snap.Comments)-1].Time + return time.Unix(lastEditTimestamp, 0) +} diff --git a/commands/ls.go b/commands/ls.go index 2101dc84ea23b12439a0462c22b2bb5d14e1d146..631afb5eb147135b0ceaf66784cb1a1c4a131705 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -22,7 +22,7 @@ func RunLsBug(repo repository.Repo, args []string) error { snapshot := bug.Compile() - fmt.Printf("%s %s\n", bug.HumanId(), snapshot.Title) + fmt.Printf("%s %s\t%s\n", bug.HumanId(), snapshot.Title, snapshot.Summary()) } return nil