aboutsummaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-02 16:35:13 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-02 16:35:13 +0200
commitae1ed6c11f3ae5675c80f377dd7f3996b3d621d0 (patch)
tree85c4b12e0ebdbbbe43938ac1fa6d9f751a782ab3 /input
parente6a64b4985f5d342b8e75fecaf4d138f4f50487e (diff)
downloadgit-bug-ae1ed6c11f3ae5675c80f377dd7f3996b3d621d0.tar.gz
termui: implement addComment and setTitle
Diffstat (limited to 'input')
-rw-r--r--input/input.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/input/input.go b/input/input.go
index 300348af..530106e2 100644
--- a/input/input.go
+++ b/input/input.go
@@ -102,6 +102,41 @@ func BugCommentEditorInput(repo repository.Repo) (string, error) {
return message, nil
}
+const bugTitleTemplate = `
+
+# Please enter the new title. Only one line will used.
+# Lines starting with '#' will be ignored, and an empty title aborts the operation.
+`
+
+func BugTitleEditorInput(repo repository.Repo) (string, error) {
+ raw, err := LaunchEditorWithTemplate(repo, messageFilename, bugTitleTemplate)
+
+ if err != nil {
+ return "", err
+ }
+
+ 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
+}
+
func LaunchEditorWithTemplate(repo repository.Repo, fileName string, template string) (string, error) {
path := fmt.Sprintf("%s/.git/%s", repo.GetPath(), fileName)