aboutsummaryrefslogtreecommitdiffstats
path: root/commands/new.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-31 15:18:09 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-31 16:44:23 +0200
commiteb39c5c29bc0e9b5e15a940a1b71bdac688b6535 (patch)
tree5ef9b827f4a3097e4eb1367097d0059f895befbe /commands/new.go
parent8a4e373e7b1c093abeb967d9a6a43c5ed533edb8 (diff)
downloadgit-bug-eb39c5c29bc0e9b5e15a940a1b71bdac688b6535.tar.gz
cli: rework new and comment command to better use the editor
a nice templace is now provided with explanations new: title and message can now be provided from the editor. Title will be the first non-empty line
Diffstat (limited to 'commands/new.go')
-rw-r--r--commands/new.go36
1 files changed, 18 insertions, 18 deletions
diff --git a/commands/new.go b/commands/new.go
index 4168453e..88e7cd81 100644
--- a/commands/new.go
+++ b/commands/new.go
@@ -1,39 +1,36 @@
package commands
import (
- "errors"
"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/input"
"github.com/spf13/cobra"
)
var (
- newMessageFile string
+ newTitle string
newMessage string
+ newMessageFile string
)
func runNewBug(cmd *cobra.Command, args []string) error {
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 newMessage == "" || newTitle == "" {
+ newTitle, newMessage, err = input.BugCreateEditorInput(repo, messageFilename, newTitle, newMessage)
+
+ if err == input.ErrEmptyTitle {
+ fmt.Println("Empty title, aborting.")
+ return nil
+ }
if err != nil {
return err
}
@@ -44,7 +41,7 @@ func runNewBug(cmd *cobra.Command, args []string) error {
return err
}
- newBug, err := operations.Create(author, title, newMessage)
+ newBug, err := operations.Create(author, newTitle, newMessage)
if err != nil {
return err
}
@@ -61,7 +58,7 @@ func runNewBug(cmd *cobra.Command, args []string) error {
}
var newCmd = &cobra.Command{
- Use: "new <title> [<option>...]",
+ Use: "new [<option>...]",
Short: "Create a new bug",
RunE: runNewBug,
}
@@ -69,10 +66,13 @@ var newCmd = &cobra.Command{
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(&newTitle, "title", "t", "",
+ "Provide a title to describe the issue",
)
newCmd.Flags().StringVarP(&newMessage, "message", "m", "",
"Provide a message to describe the issue",
)
+ newCmd.Flags().StringVarP(&newMessageFile, "file", "F", "",
+ "Take the message from the given file. Use - to read the message from the standard input",
+ )
}