Detailed changes
@@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"
"github.com/git-bug/git-bug/cache"
- buginput "github.com/git-bug/git-bug/commands/bug/input"
+ boardinput "github.com/git-bug/git-bug/commands/board/input"
"github.com/git-bug/git-bug/commands/execenv"
_select "github.com/git-bug/git-bug/commands/select"
"github.com/git-bug/git-bug/entity"
@@ -15,8 +15,7 @@ import (
type boardAddDraftOptions struct {
title string
- messageFile string
- message string
+ titleFile string
column string
nonInteractive bool
}
@@ -40,10 +39,8 @@ func newBoardAddDraftCommand() *cobra.Command {
flags.StringVarP(&options.title, "title", "t", "",
"Provide the title to describe the draft item")
- flags.StringVarP(&options.message, "message", "m", "",
- "Provide the message of the draft item")
- flags.StringVarP(&options.messageFile, "file", "F", "",
- "Take the message from the given file. Use - to read the message from the standard input")
+ flags.StringVarP(&options.titleFile, "file", "F", "",
+ "Take the title from the given file. Use - to read the message from the standard input")
flags.StringVarP(&options.column, "column", "c", "1",
"The column to add to. Either a column Id or prefix, or the column number starting from 1.")
_ = cmd.RegisterFlagCompletionFunc("column", ColumnCompletion(env))
@@ -58,19 +55,16 @@ func runBoardAddDraft(env *execenv.Env, opts boardAddDraftOptions, args []string
return err
}
- // TODO: editor with single line, no message
-
- if opts.messageFile != "" && opts.message == "" {
- // Note: reuse the bug inputs
- opts.title, opts.message, err = buginput.BugCreateFileInput(opts.messageFile)
+ if opts.titleFile != "" && opts.title == "" {
+ opts.title, err = boardinput.BoardTitleFileInput(opts.titleFile)
if err != nil {
return err
}
}
- if !opts.nonInteractive && opts.messageFile == "" && (opts.message == "" || opts.title == "") {
- opts.title, opts.message, err = buginput.BugCreateEditorInput(env.Backend, opts.title, opts.message)
- if err == buginput.ErrEmptyTitle {
+ if !opts.nonInteractive && opts.titleFile == "" && opts.title == "" {
+ opts.title, err = boardinput.BoardTitleEditorInput(env.Backend, opts.title)
+ if err == boardinput.ErrEmptyTitle {
env.Out.Println("Empty title, aborting.")
return nil
}
@@ -0,0 +1,69 @@
+package buginput
+
+import (
+ "fmt"
+ "strings"
+
+ "github.com/pkg/errors"
+
+ "github.com/git-bug/git-bug/commands/input"
+ "github.com/git-bug/git-bug/repository"
+)
+
+const messageFilename = "BOARD_EDITMSG"
+
+// ErrEmptyTitle is returned when the required title has not been entered
+var ErrEmptyTitle = errors.New("empty title")
+
+const boardTitleTemplate = `%s
+
+# Please enter the title of the draft board item. Only one line will used.
+# Lines starting with '#' will be ignored, and an empty title aborts the operation.
+`
+
+// BoardTitleEditorInput will open the default editor in the terminal with a
+// template for the user to fill. The file is then processed to extract the title.
+func BoardTitleEditorInput(repo repository.RepoCommonStorage, preTitle string) (string, error) {
+ template := fmt.Sprintf(boardTitleTemplate, preTitle)
+
+ raw, err := input.LaunchEditorWithTemplate(repo, messageFilename, template)
+ if err != nil {
+ return "", err
+ }
+
+ return processTitle(raw)
+}
+
+// BoardTitleFileInput read from either from a file or from the standard input
+// and extract a title.
+func BoardTitleFileInput(fileName string) (string, error) {
+ raw, err := input.FromFile(fileName)
+ if err != nil {
+ return "", err
+ }
+
+ return processTitle(raw)
+}
+
+func processTitle(raw string) (string, error) {
+ lines := strings.Split(raw, "\n")
+
+ var title string
+ for _, line := range lines {
+ if strings.HasPrefix(line, "#") {
+ continue
+ }
+ trimmed := strings.TrimSpace(line)
+ if trimmed == "" {
+ continue
+ }
+ title = trimmed
+ break
+ }
+
+ if title == "" {
+ return "", ErrEmptyTitle
+ }
+
+ return title, nil
+}
@@ -11,7 +11,7 @@ import (
"github.com/git-bug/git-bug/repository"
)
-const messageFilename = "BUG_MESSAGE_EDITMSG"
+const messageFilename = "BUG_EDITMSG"
// ErrEmptyMessage is returned when the required message has not been entered
var ErrEmptyMessage = errors.New("empty message")
@@ -197,7 +197,7 @@ const queryTemplate = `%s
# - sort:edit, sort:edit-desc, sort:edit-asc
#
# Notes
-#
+#
# - queries are case insensitive.
# - you can combine as many qualifiers as you want.
# - you can use double quotes for multi-word search terms (ex: author:"RenΓ© Descartes")
@@ -17,13 +17,9 @@ Add a draft item to a board
\fB-t\fP, \fB--title\fP=""
Provide the title to describe the draft item
-.PP
-\fB-m\fP, \fB--message\fP=""
- Provide the message of the draft item
-
.PP
\fB-F\fP, \fB--file\fP=""
- Take the message from the given file. Use - to read the message from the standard input
+ Take the title from the given file. Use - to read the message from the standard input
.PP
\fB-c\fP, \fB--column\fP="1"
@@ -10,8 +10,7 @@ git-bug board add-draft [BOARD_ID] [flags]
```
-t, --title string Provide the title to describe the draft item
- -m, --message string Provide the message of the draft item
- -F, --file string Take the message from the given file. Use - to read the message from the standard input
+ -F, --file string Take the title from the given file. Use - to read the message from the standard input
-c, --column string The column to add to. Either a column Id or prefix, or the column number starting from 1. (default "1")
--non-interactive Do not ask for user input
-h, --help help for add-draft