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.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/ipc/send.go b/lib/ipc/send.go
index 5cc97cc0..522e944a 100644
--- a/lib/ipc/send.go
+++ b/lib/ipc/send.go
@@ -10,14 +10,20 @@ import (
"github.com/kyoh86/xdg"
)
-func ConnectAndExec(msg string) error {
+func ConnectAndExec(args []string) error {
sockpath := path.Join(xdg.RuntimeDir(), "aerc.sock")
conn, err := net.Dial("unix", sockpath)
if err != nil {
return err
}
defer conn.Close()
- _, err = conn.Write([]byte(msg + "\n"))
+
+ req, err := (&Request{Arguments: args}).Encode()
+ if err != nil {
+ return 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)
}
@@ -25,7 +31,17 @@ func ConnectAndExec(msg string) error {
if !scanner.Scan() {
return errors.New("No response from server")
}
- result := scanner.Text()
- fmt.Println(result)
+ resp, err := DecodeResponse(scanner.Bytes())
+ if err != nil {
+ return err
+ }
+
+ // TODO: handle this in a more elegant manner
+ if resp.Error == "" {
+ fmt.Println("result: success")
+ } else {
+ fmt.Println("result: ", resp.Error)
+ }
+
return nil
}