aboutsummaryrefslogtreecommitdiffstats
path: root/commands/ls.go
blob: 0d18883394f50010eb5182bd7a0402161d94aeab (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package commands

import (
	"fmt"
	b "github.com/MichaelMure/git-bug/bug"
	"github.com/MichaelMure/git-bug/repository"
	"github.com/MichaelMure/git-bug/util"
)

func runLsBug(repo repository.Repo, args []string) error {
	ids, err := repo.ListRefs(b.BugsRefPattern)

	if err != nil {
		return err
	}

	for _, ref := range ids {
		bug, err := b.ReadBug(repo, b.BugsRefPattern+ref)

		if err != nil {
			return err
		}

		snapshot := bug.Compile()

		var author b.Person

		if len(snapshot.Comments) > 0 {
			create := snapshot.Comments[0]
			author = create.Author
		}

		// truncate + pad if needed
		titleFmt := fmt.Sprintf("%-50.50s", snapshot.Title)
		authorFmt := fmt.Sprintf("%-15.15s", author.Name)

		fmt.Printf("%s %s\t%s\t%s\t%s\n",
			util.Cyan(bug.HumanId()),
			util.Yellow(snapshot.Status),
			titleFmt,
			util.Magenta(authorFmt),
			snapshot.Summary(),
		)
	}

	return nil
}

var lsCmd = &Command{
	Description: "Display a summary of all bugs",
	Usage:       "",
	RunMethod:   runLsBug,
}