diff options
Diffstat (limited to 'commands/comment.go')
-rw-r--r-- | commands/comment.go | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/commands/comment.go b/commands/comment.go index 9815dac4..ce40d2e3 100644 --- a/commands/comment.go +++ b/commands/comment.go @@ -2,24 +2,18 @@ package commands import ( "errors" - "flag" "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/bug/operations" "github.com/MichaelMure/git-bug/commands/input" - "github.com/MichaelMure/git-bug/repository" + "github.com/spf13/cobra" ) -var commentFlagSet = flag.NewFlagSet("comment", flag.ExitOnError) - var ( - commentMessageFile = commentFlagSet.String("F", "", "Take the message from the given file. Use - to read the message from the standard input") - commentMessage = commentFlagSet.String("m", "", "Provide the new message from the command line") + commentMessageFile string + commentMessage string ) -func runComment(repo repository.Repo, args []string) error { - commentFlagSet.Parse(args) - args = commentFlagSet.Args() - +func runComment(cmd *cobra.Command, args []string) error { var err error if len(args) > 1 { @@ -32,14 +26,14 @@ func runComment(repo repository.Repo, args []string) error { prefix := args[0] - if *commentMessageFile != "" && *commentMessage == "" { - *commentMessage, err = input.FromFile(*commentMessageFile) + if commentMessageFile != "" && commentMessage == "" { + commentMessage, err = input.FromFile(commentMessageFile) if err != nil { return err } } - if *commentMessageFile == "" && *commentMessage == "" { - *commentMessage, err = input.LaunchEditor(repo, messageFilename) + if commentMessageFile == "" && commentMessage == "" { + commentMessage, err = input.LaunchEditor(repo, messageFilename) if err != nil { return err } @@ -55,7 +49,7 @@ func runComment(repo repository.Repo, args []string) error { return err } - addCommentOp := operations.NewAddCommentOp(author, *commentMessage) + addCommentOp := operations.NewAddCommentOp(author, commentMessage) b.Append(addCommentOp) @@ -64,9 +58,20 @@ func runComment(repo repository.Repo, args []string) error { return err } -var commentCmd = &Command{ - Description: "Add a new comment to a bug", - Usage: "[<options>...] <id>", - flagSet: commentFlagSet, - RunMethod: runComment, +var commentCmd = &cobra.Command{ + Use: "comment <id> [<options>...]", + Short: "Add a new comment to a bug", + RunE: runComment, +} + +func init() { + rootCmd.AddCommand(commentCmd) + + 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", + ) } |