From 5eeeae7cdf24083277076041c4e8cdc6b4737fda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Thu, 11 Apr 2019 20:04:44 +0200 Subject: [PATCH] commands: fix ls not displaying the new Identities properly --- cache/bug_excerpt.go | 14 ++++++++++++++ commands/ls.go | 14 +++++++++++++- doc/man/git-bug-ls.1 | 8 ++++++++ doc/man/git-bug-show.1 | 2 +- doc/md/git-bug_ls.md | 18 ++++++++++-------- doc/md/git-bug_show.md | 2 +- misc/bash_completion/git-bug | 6 ++++++ 7 files changed, 53 insertions(+), 11 deletions(-) diff --git a/cache/bug_excerpt.go b/cache/bug_excerpt.go index d78def4e0c5ebece588a14c40c223f1cd7f93b54..8e9e5e37e7848a48b1403b4b2d8a93180a5d288a 100644 --- a/cache/bug_excerpt.go +++ b/cache/bug_excerpt.go @@ -2,6 +2,7 @@ package cache import ( "encoding/gob" + "fmt" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/identity" @@ -45,6 +46,19 @@ type LegacyAuthorExcerpt struct { Login string } +func (l LegacyAuthorExcerpt) DisplayName() string { + switch { + case l.Name == "" && l.Login != "": + return l.Login + case l.Name != "" && l.Login == "": + return l.Name + case l.Name != "" && l.Login != "": + return fmt.Sprintf("%s (%s)", l.Name, l.Login) + } + + panic("invalid person data") +} + func NewBugExcerpt(b bug.Interface, snap *bug.Snapshot) *BugExcerpt { participantsIds := make([]string, len(snap.Participants)) for i, participant := range snap.Participants { diff --git a/commands/ls.go b/commands/ls.go index ca74cc462b4bee875d3643c6f908da5bbb225e99..22940f2f0297cf0139438b0318bc0cf841903278 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -52,9 +52,21 @@ func runLsBug(cmd *cobra.Command, args []string) error { return err } + var name string + if b.AuthorId != "" { + author, err := backend.ResolveIdentityExcerpt(b.AuthorId) + if err != nil { + name = "" + } else { + name = author.DisplayName() + } + } else { + name = b.LegacyAuthor.DisplayName() + } + // truncate + pad if needed titleFmt := fmt.Sprintf("%-50.50s", b.Title) - authorFmt := fmt.Sprintf("%-15.15s", b.LegacyAuthor.Name) + authorFmt := fmt.Sprintf("%-15.15s", name) fmt.Printf("%s %s\t%s\t%s\tC:%d L:%d\n", colors.Cyan(b.HumanId()), diff --git a/doc/man/git-bug-ls.1 b/doc/man/git-bug-ls.1 index 3d2bc4e80341d3c81ce1a0d62626e71a3dd245ae..aae57c1d1cdc6ed59ad45467113ff13a0305020f 100644 --- a/doc/man/git-bug-ls.1 +++ b/doc/man/git-bug-ls.1 @@ -30,6 +30,14 @@ You can pass an additional query to filter and order the list. This query can be \fB\-a\fP, \fB\-\-author\fP=[] Filter by author +.PP +\fB\-p\fP, \fB\-\-participant\fP=[] + Filter by participant + +.PP +\fB\-A\fP, \fB\-\-actor\fP=[] + Filter by actor + .PP \fB\-l\fP, \fB\-\-label\fP=[] Filter by label diff --git a/doc/man/git-bug-show.1 b/doc/man/git-bug-show.1 index 3dfb44193bdfc31e76a06c93ef0819471a94718f..9ad9c01988b23ae5fbd3340779c96a017a3947d1 100644 --- a/doc/man/git-bug-show.1 +++ b/doc/man/git-bug-show.1 @@ -21,7 +21,7 @@ Display the details of a bug. .SH OPTIONS .PP \fB\-f\fP, \fB\-\-field\fP="" - Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title] + Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants] .PP \fB\-h\fP, \fB\-\-help\fP[=false] diff --git a/doc/md/git-bug_ls.md b/doc/md/git-bug_ls.md index 9ab71884851250686d64f78338bce8a721451ca2..085a70c956791aef922d45cce5d5c85b9913c99d 100644 --- a/doc/md/git-bug_ls.md +++ b/doc/md/git-bug_ls.md @@ -26,14 +26,16 @@ git bug ls --status closed --by creation ### Options ``` - -s, --status strings Filter by status. Valid values are [open,closed] - -a, --author strings Filter by author - -l, --label strings Filter by label - -t, --title strings Filter by title - -n, --no strings Filter by absence of something. Valid values are [label] - -b, --by string Sort the results by a characteristic. Valid values are [id,creation,edit] (default "creation") - -d, --direction string Select the sorting direction. Valid values are [asc,desc] (default "asc") - -h, --help help for ls + -s, --status strings Filter by status. Valid values are [open,closed] + -a, --author strings Filter by author + -p, --participant strings Filter by participant + -A, --actor strings Filter by actor + -l, --label strings Filter by label + -t, --title strings Filter by title + -n, --no strings Filter by absence of something. Valid values are [label] + -b, --by string Sort the results by a characteristic. Valid values are [id,creation,edit] (default "creation") + -d, --direction string Select the sorting direction. Valid values are [asc,desc] (default "asc") + -h, --help help for ls ``` ### SEE ALSO diff --git a/doc/md/git-bug_show.md b/doc/md/git-bug_show.md index 21d5460cbb465f81acca85e6178d2466081dfd90..40152ede1a1b612edeb62f305e29d9534a5c6ec4 100644 --- a/doc/md/git-bug_show.md +++ b/doc/md/git-bug_show.md @@ -13,7 +13,7 @@ git-bug show [] [flags] ### Options ``` - -f, --field string Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title] + -f, --field string Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants] -h, --help help for show ``` diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 543136b59ec7d8cbe15df53ceee7eb7838673bbe..682df96d73d542716a62b6f166817773d46a6267 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -532,6 +532,12 @@ _git-bug_ls() flags+=("--author=") two_word_flags+=("-a") local_nonpersistent_flags+=("--author=") + flags+=("--participant=") + two_word_flags+=("-p") + local_nonpersistent_flags+=("--participant=") + flags+=("--actor=") + two_word_flags+=("-A") + local_nonpersistent_flags+=("--actor=") flags+=("--label=") two_word_flags+=("-l") local_nonpersistent_flags+=("--label=")