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/commands/select"
9 "github.com/MichaelMure/git-bug/util/colors"
10 "github.com/MichaelMure/git-bug/util/interrupt"
11 "github.com/MichaelMure/git-bug/util/text"
12 "github.com/spf13/cobra"
13)
14
15func runComment(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 interrupt.RegisterCleaner(backend.Close)
22
23 b, args, err := _select.ResolveBug(backend, args)
24 if err != nil {
25 return err
26 }
27
28 snap := b.Snapshot()
29
30 commentsTextOutput(snap.Comments)
31
32 return nil
33}
34
35func commentsTextOutput(comments []bug.Comment) {
36 for i, comment := range comments {
37 if i != 0 {
38 fmt.Println()
39 }
40
41 fmt.Printf("Author: %s\n", colors.Magenta(comment.Author.DisplayName()))
42 fmt.Printf("Date: %s\n\n", comment.FormatTime())
43 fmt.Println(text.LeftPad(comment.Message, 4))
44 }
45}
46
47var commentCmd = &cobra.Command{
48 Use: "comment [<id>]",
49 Short: "Display or add comments to a bug.",
50 PreRunE: loadRepo,
51 RunE: runComment,
52}
53
54func init() {
55 RootCmd.AddCommand(commentCmd)
56
57 commentCmd.Flags().SortFlags = false
58}