bug_comment.go

 1package bugcmd
 2
 3import (
 4	text "github.com/MichaelMure/go-term-text"
 5	"github.com/spf13/cobra"
 6
 7	"github.com/MichaelMure/git-bug/commands/execenv"
 8	"github.com/MichaelMure/git-bug/util/colors"
 9)
10
11func newBugCommentCommand(env *execenv.Env) *cobra.Command {
12	cmd := &cobra.Command{
13		Use:     "comment [BUG_ID]",
14		Short:   "List a bug's comments",
15		PreRunE: execenv.LoadBackend(env),
16		RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
17			return runBugComment(env, args)
18		}),
19		ValidArgsFunction: BugCompletion(env),
20	}
21
22	cmd.AddCommand(newBugCommentNewCommand(env))
23	cmd.AddCommand(newBugCommentEditCommand(env))
24
25	return cmd
26}
27
28func runBugComment(env *execenv.Env, args []string) error {
29	b, _, err := ResolveSelected(env.Backend, args)
30	if err != nil {
31		return err
32	}
33
34	snap := b.Compile()
35
36	for i, comment := range snap.Comments {
37		if i != 0 {
38			env.Out.Println()
39		}
40
41		env.Out.Printf("Author: %s\n", colors.Magenta(comment.Author.DisplayName()))
42		env.Out.Printf("Id: %s\n", colors.Cyan(comment.CombinedId().Human()))
43		env.Out.Printf("Date: %s\n\n", comment.FormatTime())
44		env.Out.Println(text.LeftPadLines(comment.Message, 4))
45	}
46
47	return nil
48}