diff options
Diffstat (limited to 'cmd/goctl')
-rw-r--r-- | cmd/goctl/main.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/cmd/goctl/main.go b/cmd/goctl/main.go new file mode 100644 index 0000000..1537c9a --- /dev/null +++ b/cmd/goctl/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "flag" + "fmt" + "log" + "net" + "os" + "strings" + + "github.com/bjc/goctl" +) + +func main() { + var path = flag.String("path", "", "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(), " "))) + if buf, err := goctl.Read(c); err != nil { + log.Fatalf("Error reading response from command: %s.", err) + } else { + fmt.Println(string(buf)) + } +} |