|
@@ -27,12 +27,15 @@ package issues
|
|
|
import (
|
|
import (
|
|
|
"errors"
|
|
"errors"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "log"
|
|
|
"math/rand"
|
|
"math/rand"
|
|
|
"os"
|
|
"os"
|
|
|
"os/exec"
|
|
"os/exec"
|
|
|
"path/filepath"
|
|
"path/filepath"
|
|
|
"strings"
|
|
"strings"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
+
|
|
|
|
|
+ "github.com/google/shlex"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// converts file from []string to string, reports errors
|
|
// converts file from []string to string, reports errors
|
|
@@ -90,18 +93,52 @@ func ReadTemplate(path string) (lines []string, err error) {
|
|
|
return lines, err
|
|
return lines, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// InvokeEditor invokes a preconfigured editor, and reports the output and any errors.
|
|
|
|
|
|
|
+// InvokeEditor invokes the system's configured editor on the specified path,
|
|
|
|
|
+// and reports any errors.
|
|
|
|
|
+//
|
|
|
|
|
+// InvokeEditor will attempt to determine the editor command in the following
|
|
|
|
|
+// order:
|
|
|
|
|
+//
|
|
|
|
|
+// 1. The $ISSUES_EDITOR environment variable
|
|
|
|
|
+//
|
|
|
|
|
+// 2. The $GIT_CONFIG environment variable
|
|
|
|
|
+//
|
|
|
|
|
+// 3. The $EDITOR environment variable
|
|
|
|
|
+//
|
|
|
|
|
+// Finally, if no configured editor is found, the program will exit with status
|
|
|
|
|
+// code 2
|
|
|
func InvokeEditor(path string) error {
|
|
func InvokeEditor(path string) error {
|
|
|
// determine editor
|
|
// determine editor
|
|
|
// 1. Git config
|
|
// 1. Git config
|
|
|
// 2. $EDITOR
|
|
// 2. $EDITOR
|
|
|
// 3. Panic?
|
|
// 3. Panic?
|
|
|
|
|
|
|
|
|
|
+ editor := os.Getenv("ISSUES_EDITOR")
|
|
|
|
|
+ // if issue editor wasn't present, check git editor
|
|
|
|
|
+ if editor == "" {
|
|
|
|
|
+ editor = os.Getenv("GIT_EDITOR")
|
|
|
|
|
+ }
|
|
|
|
|
+ // if git editor wasn't present, check if editor set
|
|
|
|
|
+ if editor == "" {
|
|
|
|
|
+ editor = os.Getenv("EDITOR")
|
|
|
|
|
+ }
|
|
|
|
|
+ // if editor wasn't present, error out
|
|
|
|
|
+ if editor == "" {
|
|
|
|
|
+ log.Fatal("no editor set by system")
|
|
|
|
|
+ os.Exit(2)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// execute editor
|
|
// execute editor
|
|
|
- cmd := exec.Command("vim", path)
|
|
|
|
|
- cmd.Stdin = os.Stdin // capture data
|
|
|
|
|
- cmd.Stdout = os.Stdout // capture data
|
|
|
|
|
- cmd.Stderr = os.Stderr // capture data
|
|
|
|
|
|
|
+ editorCmd, err := shlex.Split(editor)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ log.Fatal("could not parse editor")
|
|
|
|
|
+ os.Exit(2)
|
|
|
|
|
+ }
|
|
|
|
|
+ editorCmd = append(editorCmd, path)
|
|
|
|
|
+ cmd := exec.Command(editorCmd[0], editorCmd[1:]...)
|
|
|
|
|
+ cmd.Stdin = os.Stdin // pass stdin to cmd
|
|
|
|
|
+ cmd.Stdout = os.Stdout // pass stdout to cmd
|
|
|
|
|
+ cmd.Stderr = os.Stderr // pass stderr to cmd
|
|
|
|
|
|
|
|
// wait for cmd and error out if err
|
|
// wait for cmd and error out if err
|
|
|
if err := cmd.Run(); err != nil {
|
|
if err := cmd.Run(); err != nil {
|