1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package askcli
import (
"context"
"io"
"codeberg.org/snonux/hexai/internal/editor"
)
// captureFromEditor opens the user's editor on a temporary file and returns its
// trimmed contents after the editor exits. It is a variable so tests can stub it.
var captureFromEditor = func() (string, error) {
return editor.OpenTempAndEdit(nil)
}
// handleEdit opens the configured editor on a temporary file and creates a new
// task from the resulting (possibly multi-line) content.
func (d *Dispatcher) handleEdit(ctx context.Context, args []string, stdout, stderr io.Writer) (int, error) {
_ = args
description, err := captureFromEditor()
if err != nil {
writeInfoError(stderr, err)
return 1, nil
}
if description == "" {
_, _ = io.WriteString(stderr, "error: ask edit aborted: empty description\n")
return 1, nil
}
return d.createTask(ctx, nil, description, nil, stdout, stderr)
}
|