Make the socket path flag actually useful

This commit is contained in:
Finn 2018-10-08 17:47:10 -07:00
parent b6bd1a79e8
commit 321fde23a2
2 changed files with 9 additions and 6 deletions

View file

@ -33,8 +33,8 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.signald-cli.yaml)")
RootCmd.PersistentFlags().StringVarP(&socketPath, "socket", "s", "/var/run/signald/signald.socket", "the path to the signald socket file")
s = &signald.Signald{}
RootCmd.PersistentFlags().StringVarP(&socketPath, "socket", "s", "/var/run/signald/signald.sock", "the path to the signald socket file")
s = &signald.Signald{SocketPath: socketPath,}
s.Connect()
}

View file

@ -2,14 +2,14 @@ package signald
import (
"encoding/json"
"net"
"log"
"net"
)
// Signald is a connection to a signald instance.
type Signald struct {
socket net.Conn
SocketPath string
}
func crash(err error) {
@ -20,7 +20,10 @@ func crash(err error) {
// Connect connects to the signad socket
func (s *Signald) Connect() {
socket, err := net.Dial("unix", "/var/run/signald/signald.sock")
if s.SocketPath == "" {
s.SocketPath = "/var/run/signald/signald.sock"
}
socket, err := net.Dial("unix", s.SocketPath)
crash(err)
s.socket = socket
log.Print("Connected to signald socket ", socket.RemoteAddr().String())