ls.go

 1package commands
 2
 3import (
 4	"fmt"
 5
 6	"github.com/MichaelMure/git-bug/bug"
 7	"github.com/MichaelMure/git-bug/util"
 8	"github.com/spf13/cobra"
 9)
10
11func runLsBug(cmd *cobra.Command, args []string) error {
12	//backend, err := cache.NewRepoCache(repo)
13	//if err != nil {
14	//	return err
15	//}
16
17	// Todo: read bugs from backend
18
19	bugs := bug.ReadAllLocalBugs(repo)
20
21	for b := range bugs {
22		if b.Err != nil {
23			return b.Err
24		}
25
26		snapshot := b.Bug.Compile()
27
28		var author bug.Person
29
30		if len(snapshot.Comments) > 0 {
31			create := snapshot.Comments[0]
32			author = create.Author
33		}
34
35		// truncate + pad if needed
36		titleFmt := fmt.Sprintf("%-50.50s", snapshot.Title)
37		authorFmt := fmt.Sprintf("%-15.15s", author.Name)
38
39		fmt.Printf("%s %s\t%s\t%s\t%s\n",
40			util.Cyan(b.Bug.HumanId()),
41			util.Yellow(snapshot.Status),
42			titleFmt,
43			util.Magenta(authorFmt),
44			snapshot.Summary(),
45		)
46	}
47
48	return nil
49}
50
51var lsCmd = &cobra.Command{
52	Use:   "ls",
53	Short: "Display a summary of all bugs",
54	RunE:  runLsBug,
55}
56
57func init() {
58	RootCmd.AddCommand(lsCmd)
59}