1package commands
2
3import (
4 "errors"
5 "fmt"
6 "strings"
7
8 "github.com/MichaelMure/git-bug/cache"
9 "github.com/MichaelMure/git-bug/cleaner"
10 "github.com/MichaelMure/git-bug/commands/select"
11 "github.com/MichaelMure/git-bug/util/colors"
12 "github.com/spf13/cobra"
13)
14
15func runShowBug(cmd *cobra.Command, args []string) error {
16 backend, err := cache.NewRepoCache(repo)
17 if err != nil {
18 return err
19 }
20 defer backend.Close()
21 cleaner.Register(backend.Close)
22
23 b, args, err := _select.ResolveBug(backend, args)
24 if err != nil {
25 return err
26 }
27
28 snapshot := b.Snapshot()
29
30 if len(snapshot.Comments) == 0 {
31 return errors.New("Invalid bug: no comment")
32 }
33
34 firstComment := snapshot.Comments[0]
35
36 // Header
37 fmt.Printf("[%s] %s %s\n\n",
38 colors.Yellow(snapshot.Status),
39 colors.Cyan(snapshot.HumanId()),
40 snapshot.Title,
41 )
42
43 fmt.Printf("%s opened this issue %s\n\n",
44 colors.Magenta(firstComment.Author.DisplayName()),
45 firstComment.FormatTimeRel(),
46 )
47
48 var labels = make([]string, len(snapshot.Labels))
49 for i := range snapshot.Labels {
50 labels[i] = string(snapshot.Labels[i])
51 }
52
53 fmt.Printf("labels: %s\n\n",
54 strings.Join(labels, ", "),
55 )
56
57 // Comments
58 indent := " "
59
60 for i, comment := range snapshot.Comments {
61 fmt.Printf("%s#%d %s <%s>\n\n",
62 indent,
63 i,
64 comment.Author.DisplayName(),
65 comment.Author.Email,
66 )
67
68 fmt.Printf("%s%s\n\n\n",
69 indent,
70 comment.Message,
71 )
72 }
73
74 return nil
75}
76
77var showCmd = &cobra.Command{
78 Use: "show [<id>]",
79 Short: "Display the details of a bug",
80 PreRunE: loadRepo,
81 RunE: runShowBug,
82}
83
84func init() {
85 RootCmd.AddCommand(showCmd)
86}