1package commands
2
3import (
4 "fmt"
5
6 "github.com/MichaelMure/git-bug/bug"
7 "github.com/MichaelMure/git-bug/cache"
8 "github.com/MichaelMure/git-bug/util"
9 "github.com/spf13/cobra"
10)
11
12func runLsBug(cmd *cobra.Command, args []string) error {
13 backend, err := cache.NewRepoCache(repo)
14 if err != nil {
15 return err
16 }
17
18 allIds := backend.AllBugsId(cache.OrderByCreation, cache.OrderAscending)
19
20 for _, id := range allIds {
21 b, err := backend.ResolveBug(id)
22 if err != nil {
23 return err
24 }
25
26 snapshot := b.Snapshot()
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.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}