2018-07-12 13:44:46 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2018-07-13 17:13:40 +03:00
|
|
|
"errors"
|
2018-07-12 13:44:46 +03:00
|
|
|
"flag"
|
2018-07-17 02:52:56 +03:00
|
|
|
"fmt"
|
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-12 13:44:46 +03:00
|
|
|
"github.com/MichaelMure/git-bug/commands/input"
|
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
|
|
|
)
|
|
|
|
|
|
|
|
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")
|
|
|
|
)
|
|
|
|
|
2018-07-15 10:26:11 +03:00
|
|
|
func runNewBug(repo repository.Repo, args []string) error {
|
2018-07-12 13:44:46 +03:00
|
|
|
newFlagSet.Parse(args)
|
|
|
|
args = newFlagSet.Args()
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if len(args) == 0 {
|
|
|
|
return errors.New("No title provided")
|
|
|
|
}
|
|
|
|
if len(args) > 1 {
|
|
|
|
return errors.New("Only accepting one title is supported")
|
|
|
|
}
|
|
|
|
|
|
|
|
title := args[0]
|
|
|
|
|
|
|
|
if *newMessageFile != "" && *newMessage == "" {
|
|
|
|
*newMessage, err = input.FromFile(*newMessageFile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if *newMessageFile == "" && *newMessage == "" {
|
|
|
|
*newMessage, err = input.LaunchEditor(repo, messageFilename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
author, err := bug.GetUser(repo)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-07-13 17:13:40 +03:00
|
|
|
newbug, err := bug.NewBug()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-07-12 13:44:46 +03:00
|
|
|
}
|
|
|
|
|
2018-07-13 17:13:40 +03:00
|
|
|
createOp := operations.NewCreateOp(author, title, *newMessage)
|
2018-07-12 13:44:46 +03:00
|
|
|
|
2018-07-13 17:13:40 +03:00
|
|
|
newbug.Append(createOp)
|
2018-07-12 16:14:37 +03:00
|
|
|
|
2018-07-14 23:17:37 +03:00
|
|
|
err = newbug.Commit(repo)
|
|
|
|
|
2018-07-17 02:52:56 +03:00
|
|
|
fmt.Println(newbug.HumanId())
|
|
|
|
|
2018-07-14 23:17:37 +03:00
|
|
|
return err
|
2018-07-12 13:44:46 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var newCmd = &Command{
|
2018-07-16 16:21:21 +03:00
|
|
|
Description: "Create a new bug",
|
|
|
|
Usage: "[<option>...] <title>",
|
|
|
|
flagSet: newFlagSet,
|
|
|
|
RunMethod: runNewBug,
|
2018-07-12 13:44:46 +03:00
|
|
|
}
|