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