From bfb5e96aab9e78f05942151060cc92fdaa32bedd Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 15 Sep 2018 20:30:31 +0200 Subject: commands: git bug comment now show the comments of a bug --- commands/comment.go | 58 ++++++++++++++++++----------------------------------- 1 file changed, 20 insertions(+), 38 deletions(-) (limited to 'commands/comment.go') diff --git a/commands/comment.go b/commands/comment.go index 4c516358..46267979 100644 --- a/commands/comment.go +++ b/commands/comment.go @@ -4,16 +4,13 @@ import ( "errors" "fmt" + "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/cache" - "github.com/MichaelMure/git-bug/input" + "github.com/MichaelMure/git-bug/util/colors" + "github.com/MichaelMure/git-bug/util/text" "github.com/spf13/cobra" ) -var ( - commentMessageFile string - commentMessage string -) - func runComment(cmd *cobra.Command, args []string) error { var err error @@ -33,40 +30,33 @@ func runComment(cmd *cobra.Command, args []string) error { prefix := args[0] - if commentMessageFile != "" && commentMessage == "" { - commentMessage, err = input.FromFile(commentMessageFile) - if err != nil { - return err - } - } - - if commentMessage == "" { - commentMessage, err = input.BugCommentEditorInput(backend.Repository()) - if err == input.ErrEmptyMessage { - fmt.Println("Empty message, aborting.") - return nil - } - if err != nil { - return err - } - } - b, err := backend.ResolveBugPrefix(prefix) if err != nil { return err } - err = b.AddComment(commentMessage) - if err != nil { - return err - } + snap := b.Snapshot() + + commentsTextOutput(snap.Comments) + + return nil +} - return b.Commit() +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)) + } } var commentCmd = &cobra.Command{ Use: "comment ", - Short: "Add a new comment to a bug", + Short: "Show a bug's comments", RunE: runComment, } @@ -74,12 +64,4 @@ func init() { RootCmd.AddCommand(commentCmd) commentCmd.Flags().SortFlags = false - - commentCmd.Flags().StringVarP(&commentMessageFile, "file", "F", "", - "Take the message from the given file. Use - to read the message from the standard input", - ) - - commentCmd.Flags().StringVarP(&commentMessage, "message", "m", "", - "Provide the new message from the command line", - ) } -- cgit