openFile opens filename in the preferred text editor, resolving the arguments with editor specific logic.
(filename string, infoFn func())
| 38 | // openFile opens filename in the preferred text editor, resolving the |
| 39 | // arguments with editor specific logic. |
| 40 | func (p *editorPrompt) openFile(filename string, infoFn func()) error { |
| 41 | args, err := parseEditorArgs(p.cmd) |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | args = append(args, filename) |
| 46 | |
| 47 | isCLIEditor := false |
| 48 | for _, e := range cliEditors { |
| 49 | if e == args[0] { |
| 50 | isCLIEditor = true |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | editorExe, err := exec.LookPath(args[0]) |
| 55 | if err != nil { |
| 56 | return err |
| 57 | } |
| 58 | |
| 59 | cmd := exec.Command(editorExe, args[1:]...) |
| 60 | cmd.Stdin = iostream.Input |
| 61 | cmd.Stdout = iostream.Output |
| 62 | cmd.Stderr = iostream.Messages |
| 63 | |
| 64 | if !isCLIEditor && infoFn != nil { |
| 65 | infoFn() |
| 66 | } |
| 67 | |
| 68 | return cmd.Run() |
| 69 | } |
| 70 | |
| 71 | // captureInput opens a temporary file in a text editor and returns |
| 72 | // the written bytes on success or an error on failure. It handles deletion |
no test coverage detected