2018-07-15 10:26:11 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2018-07-31 16:18:09 +03:00
|
|
|
"fmt"
|
2018-08-13 19:32:11 +03:00
|
|
|
|
2018-09-15 21:30:31 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bug"
|
2018-08-31 14:18:03 +03:00
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
2018-09-18 14:28:01 +03:00
|
|
|
"github.com/MichaelMure/git-bug/commands/select"
|
2018-09-15 21:30:31 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/colors"
|
|
|
|
"github.com/MichaelMure/git-bug/util/text"
|
2018-07-19 13:30:25 +03:00
|
|
|
"github.com/spf13/cobra"
|
2018-07-15 10:26:11 +03:00
|
|
|
)
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
func runComment(cmd *cobra.Command, args []string) error {
|
2018-08-31 14:18:03 +03:00
|
|
|
backend, err := cache.NewRepoCache(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer backend.Close()
|
|
|
|
|
2018-09-18 14:28:01 +03:00
|
|
|
b, args, err := _select.ResolveBug(backend, args)
|
2018-07-15 10:26:11 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-09-15 21:30:31 +03:00
|
|
|
snap := b.Snapshot()
|
|
|
|
|
|
|
|
commentsTextOutput(snap.Comments)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2018-07-15 10:26:11 +03:00
|
|
|
|
2018-09-15 21:30:31 +03:00
|
|
|
func commentsTextOutput(comments []bug.Comment) {
|
|
|
|
for i, comment := range comments {
|
|
|
|
if i != 0 {
|
|
|
|
fmt.Println()
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Printf("Author: %s\n", colors.Magenta(comment.Author))
|
|
|
|
fmt.Printf("Date: %s\n\n", comment.FormatTime())
|
|
|
|
fmt.Println(text.LeftPad(comment.Message, 4))
|
|
|
|
}
|
2018-07-15 10:26:11 +03:00
|
|
|
}
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
var commentCmd = &cobra.Command{
|
2018-09-18 14:28:01 +03:00
|
|
|
Use: "comment [<id>]",
|
2018-09-15 21:30:31 +03:00
|
|
|
Short: "Show a bug's comments",
|
2018-07-19 13:30:25 +03:00
|
|
|
RunE: runComment,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-07-20 16:46:14 +03:00
|
|
|
RootCmd.AddCommand(commentCmd)
|
2018-07-19 13:30:25 +03:00
|
|
|
|
2018-09-10 19:16:16 +03:00
|
|
|
commentCmd.Flags().SortFlags = false
|
2018-07-15 10:26:11 +03:00
|
|
|
}
|