From bad05a4f3d24eb092724f667ee33bb1956457dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Tue, 26 Feb 2019 22:25:52 +0100 Subject: [PATCH] cache: better API to access excerpts --- cache/repo_cache.go | 32 ++++++++++++++++++++------------ commands/user_list.go | 7 ++++++- misc/zsh_completion/git-bug | 18 +++++++++--------- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/cache/repo_cache.go b/cache/repo_cache.go index 7423ee7300bf1055c923c8d1b0c01bfd2ee2d541..2b0fa360592cb71bc7d574f765c00290515508a0 100644 --- a/cache/repo_cache.go +++ b/cache/repo_cache.go @@ -387,6 +387,16 @@ func (c *RepoCache) ResolveBug(id string) (*BugCache, error) { return cached, nil } +// ResolveBugExcerpt retrieve a BugExcerpt matching the exact given id +func (c *RepoCache) ResolveBugExcerpt(id string) (*BugExcerpt, error) { + e, ok := c.bugExcerpts[id] + if !ok { + return nil, bug.ErrBugNotExist + } + + return e, nil +} + // ResolveBugPrefix retrieve a bug matching an id prefix. It fails if multiple // bugs match. func (c *RepoCache) ResolveBugPrefix(prefix string) (*BugCache, error) { @@ -489,12 +499,6 @@ func (c *RepoCache) AllBugsIds() []string { return result } -// AllBugExcerpt return all known bug excerpt. -// This maps is read-only. -func (c *RepoCache) AllBugExcerpt() map[string]*BugExcerpt { - return c.bugExcerpts -} - // ValidLabels list valid labels // // Note: in the future, a proper label policy could be implemented where valid @@ -708,6 +712,16 @@ func (c *RepoCache) ResolveIdentity(id string) (*IdentityCache, error) { return cached, nil } +// ResolveIdentityExcerpt retrieve a IdentityExcerpt matching the exact given id +func (c *RepoCache) ResolveIdentityExcerpt(id string) (*IdentityExcerpt, error) { + e, ok := c.identitiesExcerpts[id] + if !ok { + return nil, identity.ErrIdentityNotExist + } + + return e, nil +} + // ResolveIdentityPrefix retrieve an Identity matching an id prefix. // It fails if multiple identities match. func (c *RepoCache) ResolveIdentityPrefix(prefix string) (*IdentityCache, error) { @@ -767,12 +781,6 @@ func (c *RepoCache) AllIdentityIds() []string { return result } -// AllIdentityExcerpt return all known identities excerpt. -// This maps is read-only. -func (c *RepoCache) AllIdentityExcerpt() map[string]*IdentityExcerpt { - return c.identitiesExcerpts -} - func (c *RepoCache) SetUserIdentity(i *IdentityCache) error { err := identity.SetUserIdentity(c.repo, i.Identity) if err != nil { diff --git a/commands/user_list.go b/commands/user_list.go index 19be7628932446fcf316b87520c82ba070522407..23ecea73457a0c9603b8414ad87eba3f723b7dae 100644 --- a/commands/user_list.go +++ b/commands/user_list.go @@ -17,7 +17,12 @@ func runUserLs(cmd *cobra.Command, args []string) error { defer backend.Close() interrupt.RegisterCleaner(backend.Close) - for _, i := range backend.AllIdentityExcerpt() { + for _, id := range backend.AllIdentityIds() { + i, err := backend.ResolveIdentityExcerpt(id) + if err != nil { + return err + } + fmt.Printf("%s %s\n", colors.Cyan(i.HumanId()), i.DisplayName(), diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index 9f7e84dcb23425ca79917124bcda029761c285ab..232cd3c167471f43f87c8f2db53c34ed380d7ec8 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -17,15 +17,6 @@ case $state in ;; level2) case $words[2] in - status) - _arguments '2: :(close open)' - ;; - title) - _arguments '2: :(edit)' - ;; - user) - _arguments '2: :(adopt create ls)' - ;; bridge) _arguments '2: :(configure pull rm)' ;; @@ -35,6 +26,15 @@ case $state in label) _arguments '2: :(add rm)' ;; + status) + _arguments '2: :(close open)' + ;; + title) + _arguments '2: :(edit)' + ;; + user) + _arguments '2: :(adopt create ls)' + ;; *) _arguments '*: :_files' ;;