aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ipc/send.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ipc/send.go')
-rw-r--r--lib/ipc/send.go19
1 files changed, 7 insertions, 12 deletions
diff --git a/lib/ipc/send.go b/lib/ipc/send.go
index fbe67413..d5138bf8 100644
--- a/lib/ipc/send.go
+++ b/lib/ipc/send.go
@@ -9,36 +9,31 @@ import (
"git.sr.ht/~rjarry/aerc/lib/xdg"
)
-func ConnectAndExec(args []string) error {
+func ConnectAndExec(args []string) (*Response, error) {
sockpath := xdg.RuntimePath("aerc.sock")
conn, err := net.Dial("unix", sockpath)
if err != nil {
- return err
+ return nil, err
}
defer conn.Close()
req, err := (&Request{Arguments: args}).Encode()
if err != nil {
- return fmt.Errorf("failed to encode request: %w", err)
+ return nil, fmt.Errorf("failed to encode request: %w", err)
}
_, err = conn.Write(append(req, '\n'))
if err != nil {
- return fmt.Errorf("failed to send message: %w", err)
+ return nil, fmt.Errorf("failed to send message: %w", err)
}
scanner := bufio.NewScanner(conn)
if !scanner.Scan() {
- return errors.New("No response from server")
+ return nil, errors.New("No response from server")
}
resp, err := DecodeResponse(scanner.Bytes())
if err != nil {
- return err
+ return nil, err
}
- // TODO: handle this in a more elegant manner
- if resp.Error != "" {
- fmt.Println("result: ", resp.Error)
- }
-
- return nil
+ return resp, nil
}