Skip to content

Commit bacc5f5

Browse files
committed
Add an error-message if vim is not found
Check the $PATH for vim and print an error if not found. Test plan: * Edit the $PATH and remove the entry where vim is. Run ain template! and verify there is an error-message on cannot find the default editor.
1 parent 1dce015 commit bacc5f5

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Anything after a pound sign (#) is a comment and will be ignored.
209209

210210
Ain accepts one or more template-file(s) as a mandatory parameter. As sections combine or overwrite where it makes sense you can better organize API-calls into hierarchical structures with increasing specificity. An example would be setting the [[Headers]](#Headers), [[Backend]](#backend) and [[BackendOptions]](#BackendOptions) in a base template file and then specifying the specific [[Host]](#Host), [[Method]](#Method) and [[Body]](#Body) in several template files, one for each API-endpoint. You can even use an `alias` for things you will always set.
211211

212-
Adding an exclamation-mark (!) at the end of the template file name makes ain open the file in your `$VISUAL` or `$EDITOR` or defaults to vim editor in that order so you can edit the template file. Any changes are not stored back into the template file and used only this invocation.
212+
Adding an exclamation-mark (!) at the end of the template file name makes ain open the file in your `$VISUAL` or `$EDITOR` editor or falls back to vim in that order so you can edit the template file. Any changes are not stored back into the template file and used only this invocation.
213213

214214
Example:
215215
```

internal/pkg/disk/read.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
)
1313

1414
const editFileSuffix = "!"
15+
const fallbackEditor = "vim"
1516

1617
func captureEditorOutput(tempFile *os.File) (string, error) {
1718
editorEnvVarName := "VISUAL"
@@ -23,8 +24,13 @@ func captureEditorOutput(tempFile *os.File) (string, error) {
2324
}
2425

2526
if editorEnvStr == "" {
26-
editorEnvVarName = "vim"
27-
editorEnvStr = "vim"
27+
_, err := exec.LookPath(fallbackEditor)
28+
if err != nil {
29+
return "", errors.New("Cannot find the fallback editor vim on the $PATH. Cannot edit file.")
30+
}
31+
32+
editorEnvVarName = fallbackEditor
33+
editorEnvStr = fallbackEditor
2834
}
2935

3036
editorCmdAndArgs, err := utils.TokenizeLine(editorEnvStr)

0 commit comments

Comments
 (0)