1package commands
2
3import (
4 "fmt"
5
6 "github.com/MichaelMure/git-bug/cache"
7 "github.com/MichaelMure/git-bug/util/colors"
8 "github.com/MichaelMure/git-bug/util/interrupt"
9 "github.com/spf13/cobra"
10)
11
12func runUserLs(cmd *cobra.Command, args []string) error {
13 backend, err := cache.NewRepoCache(repo)
14 if err != nil {
15 return err
16 }
17 defer backend.Close()
18 interrupt.RegisterCleaner(backend.Close)
19
20 for _, id := range backend.AllIdentityIds() {
21 i, err := backend.ResolveIdentityExcerpt(id)
22 if err != nil {
23 return err
24 }
25
26 fmt.Printf("%s %s\n",
27 colors.Cyan(i.Id.Human()),
28 i.DisplayName(),
29 )
30 }
31
32 return nil
33}
34
35var userLsCmd = &cobra.Command{
36 Use: "ls",
37 Short: "List identities.",
38 PreRunE: loadRepo,
39 RunE: runUserLs,
40}
41
42func init() {
43 userCmd.AddCommand(userLsCmd)
44 userLsCmd.Flags().SortFlags = false
45}