1package commands
2
3import (
4 "errors"
5 "fmt"
6
7 "github.com/MichaelMure/git-bug/bug"
8 "github.com/MichaelMure/git-bug/cache"
9 "github.com/MichaelMure/git-bug/util/colors"
10 "github.com/MichaelMure/git-bug/util/text"
11 "github.com/spf13/cobra"
12)
13
14func runComment(cmd *cobra.Command, args []string) error {
15 var err error
16
17 if len(args) > 1 {
18 return errors.New("Only one bug id is supported")
19 }
20
21 if len(args) == 0 {
22 return errors.New("You must provide a bug id")
23 }
24
25 backend, err := cache.NewRepoCache(repo)
26 if err != nil {
27 return err
28 }
29 defer backend.Close()
30
31 prefix := args[0]
32
33 b, err := backend.ResolveBugPrefix(prefix)
34 if err != nil {
35 return err
36 }
37
38 snap := b.Snapshot()
39
40 commentsTextOutput(snap.Comments)
41
42 return nil
43}
44
45func commentsTextOutput(comments []bug.Comment) {
46 for i, comment := range comments {
47 if i != 0 {
48 fmt.Println()
49 }
50
51 fmt.Printf("Author: %s\n", colors.Magenta(comment.Author))
52 fmt.Printf("Date: %s\n\n", comment.FormatTime())
53 fmt.Println(text.LeftPad(comment.Message, 4))
54 }
55}
56
57var commentCmd = &cobra.Command{
58 Use: "comment <id>",
59 Short: "Show a bug's comments",
60 RunE: runComment,
61}
62
63func init() {
64 RootCmd.AddCommand(commentCmd)
65
66 commentCmd.Flags().SortFlags = false
67}