aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--aerc.go11
-rw-r--r--lib/socket.go17
2 files changed, 25 insertions, 3 deletions
diff --git a/aerc.go b/aerc.go
index d44d3ba..1b313c3 100644
--- a/aerc.go
+++ b/aerc.go
@@ -94,15 +94,15 @@ var (
)
func usage() {
- log.Fatal("Usage: aerc [-v]")
+ log.Fatal("Usage: aerc [-v] [mailto:...]")
}
func main() {
- // TODO: Support starting with mailto links, ad-hoc accounts, etc
opts, optind, err := getopt.Getopts(os.Args, "v")
if err != nil {
log.Print(err)
usage()
+ return
}
for _, opt := range opts {
switch opt.Option {
@@ -111,8 +111,13 @@ func main() {
return
}
}
- if optind != len(os.Args) {
+ args := os.Args[optind:]
+ if len(args) > 1 {
usage()
+ return
+ } else if len(args) == 1 {
+ lib.ConnectAndExec(args[0])
+ return
}
var (
diff --git a/lib/socket.go b/lib/socket.go
index c256579..78e86c4 100644
--- a/lib/socket.go
+++ b/lib/socket.go
@@ -2,6 +2,7 @@ package lib
import (
"bufio"
+ "errors"
"fmt"
"log"
"net"
@@ -80,3 +81,19 @@ func (as *AercServer) handleClient(conn net.Conn) {
}
as.logger.Printf("Closed Unix connection %d", clientId)
}
+
+func ConnectAndExec(msg string) error {
+ sockpath := path.Join(xdg.RuntimeDir(), "aerc.sock")
+ conn, err := net.Dial("unix", sockpath)
+ if err != nil {
+ return err
+ }
+ conn.Write([]byte(msg + "\n"))
+ scanner := bufio.NewScanner(conn)
+ if !scanner.Scan() {
+ return errors.New("No response from server")
+ }
+ result := scanner.Text()
+ fmt.Println(result)
+ return nil
+}