aboutsummaryrefslogtreecommitdiffstats
path: root/input
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-08-13 15:28:16 +0200
committerMichael Muré <batolettre@gmail.com>2018-08-13 15:28:47 +0200
commitdf144e727a858ed07e3c9328d91efe052c4781e1 (patch)
treebfbfeea70f97ab3d4274c8e5add2c3aeeac1423b /input
parentf2f779c5a8b4efe67317bbffe110a9880c1f529a (diff)
downloadgit-bug-df144e727a858ed07e3c9328d91efe052c4781e1.tar.gz
fix some linting trouble
Diffstat (limited to 'input')
-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)