diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-15 20:30:31 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-15 20:30:31 +0200 |
commit | bfb5e96aab9e78f05942151060cc92fdaa32bedd (patch) | |
tree | ddac4640aa1b43e13dc466cad6bbaed49f172fd9 /commands | |
parent | 6b732d4535fc31e37485c7b496f2bbe0c854f661 (diff) | |
download | git-bug-bfb5e96aab9e78f05942151060cc92fdaa32bedd.tar.gz |
commands: git bug comment now show the comments of a bug
Diffstat (limited to 'commands')
-rw-r--r-- | commands/comment.go | 58 | ||||
-rw-r--r-- | commands/show.go | 2 |
2 files changed, 21 insertions, 39 deletions
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 <id>", - 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", - ) } diff --git a/commands/show.go b/commands/show.go index a45eb9b6..d4d1bb54 100644 --- a/commands/show.go +++ b/commands/show.go @@ -49,7 +49,7 @@ func runShowBug(cmd *cobra.Command, args []string) error { fmt.Printf("%s opened this issue %s\n\n", colors.Magenta(firstComment.Author.Name), - firstComment.FormatTime(), + firstComment.FormatTimeRel(), ) var labels = make([]string, len(snapshot.Labels)) |