aboutsummaryrefslogtreecommitdiffstats
path: root/input/input.go
diff options
context:
space:
mode:
Diffstat (limited to 'input/input.go')
-rw-r--r--input/input.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/input/input.go b/input/input.go
index 2986fae5..43fb9613 100644
--- a/input/input.go
+++ b/input/input.go
@@ -16,7 +16,10 @@ import (
const messageFilename = "BUG_MESSAGE_EDITMSG"
+// ErrEmptyMessage is returned when the required message has not been entered
var ErrEmptyMessage = errors.New("empty message")
+
+// ErrEmptyMessage is returned when the required title has not been entered
var ErrEmptyTitle = errors.New("empty title")
const bugTitleCommentTemplate = `%s%s
@@ -26,6 +29,9 @@ const bugTitleCommentTemplate = `%s%s
# An empty title aborts the operation.
`
+// BugCreateEditorInput will open the default editor in the terminal with a
+// template for the user to fill. The file is then processed to extract title
+// and message.
func BugCreateEditorInput(repo repository.Repo, preTitle string, preMessage string) (string, string, error) {
if preMessage != "" {
preMessage = "\n\n" + preMessage
@@ -33,7 +39,7 @@ func BugCreateEditorInput(repo repository.Repo, preTitle string, preMessage stri
template := fmt.Sprintf(bugTitleCommentTemplate, preTitle, preMessage)
- raw, err := LaunchEditorWithTemplate(repo, messageFilename, template)
+ raw, err := launchEditorWithTemplate(repo, messageFilename, template)
if err != nil {
return "", "", err
@@ -75,8 +81,10 @@ const bugCommentTemplate = `
# and an empty message aborts the operation.
`
+// BugCommentEditorInput will open the default editor in the terminal with a
+// template for the user to fill. The file is then processed to extract a comment.
func BugCommentEditorInput(repo repository.Repo) (string, error) {
- raw, err := LaunchEditorWithTemplate(repo, messageFilename, bugCommentTemplate)
+ raw, err := launchEditorWithTemplate(repo, messageFilename, bugCommentTemplate)
if err != nil {
return "", err
@@ -108,9 +116,11 @@ const bugTitleTemplate = `%s
# Lines starting with '#' will be ignored, and an empty title aborts the operation.
`
+// BugTitleEditorInput will open the default editor in the terminal with a
+// template for the user to fill. The file is then processed to extract a title.
func BugTitleEditorInput(repo repository.Repo, preTitle string) (string, error) {
template := fmt.Sprintf(bugTitleTemplate, preTitle)
- raw, err := LaunchEditorWithTemplate(repo, messageFilename, template)
+ raw, err := launchEditorWithTemplate(repo, messageFilename, template)
if err != nil {
return "", err
@@ -138,7 +148,9 @@ func BugTitleEditorInput(repo repository.Repo, preTitle string) (string, error)
return title, nil
}
-func LaunchEditorWithTemplate(repo repository.Repo, fileName string, template string) (string, error) {
+// launchEditorWithTemplate will launch an editor as launchEditor do, but with a
+// provided template.
+func launchEditorWithTemplate(repo repository.Repo, fileName string, template string) (string, error) {
path := fmt.Sprintf("%s/.git/%s", repo.GetPath(), fileName)
err := ioutil.WriteFile(path, []byte(template), 0644)
@@ -147,10 +159,10 @@ func LaunchEditorWithTemplate(repo repository.Repo, fileName string, template st
return "", err
}
- return LaunchEditor(repo, fileName)
+ return launchEditor(repo, fileName)
}
-// LaunchEditor launches the default editor configured for the given repo. This
+// launchEditor launches the default editor configured for the given repo. This
// method blocks until the editor command has returned.
//
// The specified filename should be a temporary file and provided as a relative path
@@ -159,7 +171,7 @@ func LaunchEditorWithTemplate(repo repository.Repo, fileName string, template st
//
// This method returns the text that was read from the temporary file, or
// an error if any step in the process failed.
-func LaunchEditor(repo repository.Repo, fileName string) (string, error) {
+func launchEditor(repo repository.Repo, fileName string) (string, error) {
path := fmt.Sprintf("%s/.git/%s", repo.GetPath(), fileName)
defer os.Remove(path)