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"
|
2018-10-25 00:36:39 +03:00
|
|
|
"github.com/MichaelMure/git-bug/util/interrupt"
|
2018-09-15 21:30:31 +03:00
|
|
|
"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-10-25 00:36:39 +03:00
|
|
|
interrupt.RegisterCleaner(backend.Close)
|
2018-08-31 14:18:03 +03:00
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2019-03-28 03:01:59 +03:00
|
|
|
fmt.Printf("Author: %s\n", colors.Magenta(comment.Author.DisplayName()))
|
2019-03-28 03:21:41 +03:00
|
|
|
fmt.Printf("Id: %s\n", colors.Cyan(comment.HumanId()))
|
2018-09-15 21:30:31 +03:00
|
|
|
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-10-17 21:38:10 +03:00
|
|
|
Use: "comment [<id>]",
|
2019-03-23 21:03:39 +03:00
|
|
|
Short: "Display or add comments to a bug.",
|
2018-10-17 21:38:10 +03:00
|
|
|
PreRunE: loadRepo,
|
|
|
|
RunE: runComment,
|
2018-07-19 13:30:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|