user_list.go

 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
12var (
13	userLsVerbose bool
14)
15
16func runUserLs(cmd *cobra.Command, args []string) error {
17	backend, err := cache.NewRepoCache(repo)
18	if err != nil {
19		return err
20	}
21	defer backend.Close()
22	interrupt.RegisterCleaner(backend.Close)
23
24	for _, i := range backend.AllIdentityExcerpt() {
25		fmt.Printf("%s %s\n",
26			colors.Cyan(i.HumanId()),
27			i.DisplayName(),
28		)
29	}
30
31	return nil
32}
33
34var userLsCmd = &cobra.Command{
35	Use:     "ls",
36	Short:   "List identities.",
37	PreRunE: loadRepo,
38	RunE:    runUserLs,
39}
40
41func init() {
42	userCmd.AddCommand(userLsCmd)
43	userLsCmd.Flags().SortFlags = false
44
45	userLsCmd.Flags().BoolVarP(&userLsVerbose, "verbose", "v", false,
46		"Print extra information")
47}