Trim placeholder from input via InputFromEditor
This commit is contained in:
parent
ca45159ec3
commit
6465ce5146
@ -3,6 +3,7 @@ package cli
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// InputFromEditor retrieves user input by opening an editor (one specified by
|
||||
@ -34,8 +35,15 @@ func InputFromEditor(placeholder string, pattern string) (string, error) {
|
||||
bytes, _ := os.ReadFile(msgFile.Name())
|
||||
content := string(bytes)
|
||||
|
||||
if content == placeholder {
|
||||
return "", nil
|
||||
if placeholder != "" {
|
||||
if content == placeholder {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// strip placeholder if content begins with it
|
||||
if strings.HasPrefix(content, placeholder) {
|
||||
content = content[len(placeholder):]
|
||||
}
|
||||
}
|
||||
|
||||
return content, nil
|
||||
|
Loading…
Reference in New Issue
Block a user