summaryrefslogtreecommitdiffstats
path: root/cmd/goctl/main.go
blob: 395a643f24627f3c5aac93b03e49640b51d944a4 (plain)
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
31
32
33
34
35
package main

import (
	"flag"
	"fmt"
	"log"
	"net"
	"os"
	"strings"

	"github.com/bjc/goctl"
)

func main() {
	var path = flag.String("f", "", "socket path for sending commands (required)")
	flag.Parse()

	if *path == "" {
		flag.Usage()
		os.Exit(1)
	}

	c, err := net.Dial("unix", *path)
	if err != nil {
		log.Fatalf("Couldn't connect to %s: %s.", *path, err)
	}
	defer c.Close()

	goctl.Write(c, []byte(strings.Join(flag.Args(), "\u0000")))
	if buf, err := goctl.Read(c); err != nil {
		log.Fatalf("Error reading response from command: %s.", err)
	} else {
		fmt.Println(string(buf))
	}
}