1package commands
2
3import (
4 text "github.com/MichaelMure/go-term-text"
5 "github.com/spf13/cobra"
6
7 "github.com/MichaelMure/git-bug/commands/select"
8 "github.com/MichaelMure/git-bug/util/colors"
9)
10
11func newCommentCommand() *cobra.Command {
12 env := newEnv()
13
14 cmd := &cobra.Command{
15 Use: "comment [<id>]",
16 Short: "Display or add comments to a bug.",
17 PreRunE: loadBackend(env),
18 PostRunE: closeBackend(env),
19 RunE: func(cmd *cobra.Command, args []string) error {
20 return runComment(env, args)
21 },
22 }
23
24 cmd.AddCommand(newCommentAddCommand())
25
26 return cmd
27}
28
29func runComment(env *Env, args []string) error {
30 b, args, err := _select.ResolveBug(env.backend, args)
31 if err != nil {
32 return err
33 }
34
35 snap := b.Snapshot()
36
37 for i, comment := range snap.Comments {
38 if i != 0 {
39 env.out.Println()
40 }
41
42 env.out.Printf("Author: %s\n", colors.Magenta(comment.Author.DisplayName()))
43 env.out.Printf("Id: %s\n", colors.Cyan(comment.Id().Human()))
44 env.out.Printf("Date: %s\n\n", comment.FormatTime())
45 env.out.Println(text.LeftPadLines(comment.Message, 4))
46 }
47
48 return nil
49}