summaryrefslogtreecommitdiff
path: root/internal/prompt/file.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/prompt/file.go')
-rw-r--r--internal/prompt/file.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/internal/prompt/file.go b/internal/prompt/file.go
index 365dc42..9668aed 100644
--- a/internal/prompt/file.go
+++ b/internal/prompt/file.go
@@ -17,7 +17,8 @@ var (
ErrDeleted = errors.New("deleted")
)
-func FileAction(question, content, filePath string) error {
+// TODO: Add option to randomly select another entry when no selected?
+func FileAction(question, content, filePath string) (string, error) {
colour.Info2f(filePath + ":")
fmt.Print("\n")
colour.Info2f(content)
@@ -34,22 +35,22 @@ func FileAction(question, content, filePath string) error {
switch strings.ToLower(strings.TrimSpace(input)) {
case "y", "yes":
- return nil
+ return content, nil
case "n", "no":
- return fmt.Errorf("%w %s", ErrAborted, filePath)
+ return content, fmt.Errorf("%w %s", ErrAborted, filePath)
case "e", "edit":
if err := EditFile(filePath); err != nil {
- return err
+ return content, err
}
if content, err = oi.SlurpAndTrim(filePath); err != nil {
- return err
+ return content, err
}
return FileAction(question, content, filePath)
case "d", "delete":
if err := os.Remove(filePath); err != nil {
- return err
+ return content, err
}
- return fmt.Errorf("%w %s", ErrDeleted, filePath)
+ return content, fmt.Errorf("%w %s", ErrDeleted, filePath)
default:
fmt.Println("Please enter 'y' or 'n' or 'e' or 'd'.")
}