aboutsummaryrefslogtreecommitdiffstats
path: root/commands/new.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/new.go')
-rw-r--r--commands/new.go52
1 files changed, 28 insertions, 24 deletions
diff --git a/commands/new.go b/commands/new.go
index 4f6008cf..fde944e9 100644
--- a/commands/new.go
+++ b/commands/new.go
@@ -2,25 +2,19 @@ package commands
import (
"errors"
- "flag"
"fmt"
"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 newFlagSet = flag.NewFlagSet("new", flag.ExitOnError)
-
var (
- newMessageFile = newFlagSet.String("F", "", "Take the message from the given file. Use - to read the message from the standard input")
- newMessage = newFlagSet.String("m", "", "Provide a message to describe the issue")
+ newMessageFile string
+ newMessage string
)
-func runNewBug(repo repository.Repo, args []string) error {
- newFlagSet.Parse(args)
- args = newFlagSet.Args()
-
+func runNewBug(cmd *cobra.Command, args []string) error {
var err error
if len(args) == 0 {
@@ -32,14 +26,14 @@ func runNewBug(repo repository.Repo, args []string) error {
title := args[0]
- if *newMessageFile != "" && *newMessage == "" {
- *newMessage, err = input.FromFile(*newMessageFile)
+ if newMessageFile != "" && newMessage == "" {
+ newMessage, err = input.FromFile(newMessageFile)
if err != nil {
return err
}
}
- if *newMessageFile == "" && *newMessage == "" {
- *newMessage, err = input.LaunchEditor(repo, messageFilename)
+ if newMessageFile == "" && newMessage == "" {
+ newMessage, err = input.LaunchEditor(repo, messageFilename)
if err != nil {
return err
}
@@ -50,26 +44,36 @@ func runNewBug(repo repository.Repo, args []string) error {
return err
}
- newbug, err := bug.NewBug()
+ newBug, err := bug.NewBug()
if err != nil {
return err
}
- createOp := operations.NewCreateOp(author, title, *newMessage)
+ createOp := operations.NewCreateOp(author, title, newMessage)
- newbug.Append(createOp)
+ newBug.Append(createOp)
- err = newbug.Commit(repo)
+ err = newBug.Commit(repo)
- fmt.Println(newbug.HumanId())
+ fmt.Println(newBug.HumanId())
return err
}
-var newCmd = &Command{
- Description: "Create a new bug",
- Usage: "[<option>...] <title>",
- flagSet: newFlagSet,
- RunMethod: runNewBug,
+var newCmd = &cobra.Command{
+ Use: "new <title> [<option>...]",
+ Short: "Create a new bug",
+ RunE: runNewBug,
+}
+
+func init() {
+ rootCmd.AddCommand(newCmd)
+
+ newCmd.Flags().StringVarP(&newMessageFile, "file", "F", "",
+ "Take the message from the given file. Use - to read the message from the standard input",
+ )
+ newCmd.Flags().StringVarP(&newMessage, "message", "m", "",
+ "Provide a message to describe the issue",
+ )
}