2018-07-12 13:44:46 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2018-07-17 02:52:56 +03:00
|
|
|
"fmt"
|
2018-08-13 19:32:11 +03:00
|
|
|
|
2018-07-12 13:44:46 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bug"
|
2018-07-13 17:13:40 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bug/operations"
|
2018-07-31 16:18:09 +03:00
|
|
|
"github.com/MichaelMure/git-bug/input"
|
2018-07-19 13:30:25 +03:00
|
|
|
"github.com/spf13/cobra"
|
2018-07-12 13:44:46 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2018-07-31 16:18:09 +03:00
|
|
|
newTitle string
|
2018-07-19 13:30:25 +03:00
|
|
|
newMessage string
|
2018-07-31 16:18:09 +03:00
|
|
|
newMessageFile string
|
2018-07-12 13:44:46 +03:00
|
|
|
)
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
func runNewBug(cmd *cobra.Command, args []string) error {
|
2018-07-12 13:44:46 +03:00
|
|
|
var err error
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
if newMessageFile != "" && newMessage == "" {
|
|
|
|
newMessage, err = input.FromFile(newMessageFile)
|
2018-07-12 13:44:46 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2018-07-31 16:18:09 +03:00
|
|
|
|
|
|
|
if newMessage == "" || newTitle == "" {
|
2018-07-31 17:43:43 +03:00
|
|
|
newTitle, newMessage, err = input.BugCreateEditorInput(repo, newTitle, newMessage)
|
2018-07-31 16:18:09 +03:00
|
|
|
|
|
|
|
if err == input.ErrEmptyTitle {
|
|
|
|
fmt.Println("Empty title, aborting.")
|
|
|
|
return nil
|
|
|
|
}
|
2018-07-12 13:44:46 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
author, err := bug.GetUser(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-31 16:18:09 +03:00
|
|
|
newBug, err := operations.Create(author, newTitle, newMessage)
|
2018-07-25 19:01:32 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-07-12 16:14:37 +03:00
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
err = newBug.Commit(repo)
|
2018-07-14 23:17:37 +03:00
|
|
|
|
2018-07-25 19:01:32 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-07-17 02:52:56 +03:00
|
|
|
|
2018-07-25 19:01:32 +03:00
|
|
|
fmt.Printf("%s created\n", newBug.HumanId())
|
2018-07-12 13:44:46 +03:00
|
|
|
|
2018-07-25 19:01:32 +03:00
|
|
|
return nil
|
2018-07-12 13:44:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-19 13:30:25 +03:00
|
|
|
var newCmd = &cobra.Command{
|
2018-07-31 16:18:09 +03:00
|
|
|
Use: "new [<option>...]",
|
2018-07-19 13:30:25 +03:00
|
|
|
Short: "Create a new bug",
|
|
|
|
RunE: runNewBug,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2018-07-20 16:46:14 +03:00
|
|
|
RootCmd.AddCommand(newCmd)
|
2018-07-19 13:30:25 +03:00
|
|
|
|
2018-07-31 16:18:09 +03:00
|
|
|
newCmd.Flags().StringVarP(&newTitle, "title", "t", "",
|
|
|
|
"Provide a title to describe the issue",
|
2018-07-19 13:30:25 +03:00
|
|
|
)
|
|
|
|
newCmd.Flags().StringVarP(&newMessage, "message", "m", "",
|
|
|
|
"Provide a message to describe the issue",
|
|
|
|
)
|
2018-07-31 16:18:09 +03:00
|
|
|
newCmd.Flags().StringVarP(&newMessageFile, "file", "F", "",
|
|
|
|
"Take the message from the given file. Use - to read the message from the standard input",
|
|
|
|
)
|
2018-07-12 13:44:46 +03:00
|
|
|
}
|