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