From 5eeeae7cdf24083277076041c4e8cdc6b4737fda Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Thu, 11 Apr 2019 20:04:44 +0200 Subject: 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 d78def4e..8e9e5e37 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 ca74cc46..22940f2f 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 3d2bc4e8..aae57c1d 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 3dfb4419..9ad9c019 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 9ab71884..085a70c9 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 21d5460c..40152ede 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 543136b5..682df96d 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=") -- cgit