Make the socket path flag actually useful
This commit is contained in:
parent
b6bd1a79e8
commit
321fde23a2
2 changed files with 9 additions and 6 deletions
|
@ -33,8 +33,8 @@ func Execute() {
|
||||||
func init() {
|
func init() {
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.signald-cli.yaml)")
|
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")
|
RootCmd.PersistentFlags().StringVarP(&socketPath, "socket", "s", "/var/run/signald/signald.sock", "the path to the signald socket file")
|
||||||
s = &signald.Signald{}
|
s = &signald.Signald{SocketPath: socketPath,}
|
||||||
s.Connect()
|
s.Connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,14 @@ package signald
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net"
|
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// Signald is a connection to a signald instance.
|
// Signald is a connection to a signald instance.
|
||||||
type Signald struct {
|
type Signald struct {
|
||||||
socket net.Conn
|
socket net.Conn
|
||||||
|
SocketPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func crash(err error) {
|
func crash(err error) {
|
||||||
|
@ -20,7 +20,10 @@ func crash(err error) {
|
||||||
|
|
||||||
// Connect connects to the signad socket
|
// Connect connects to the signad socket
|
||||||
func (s *Signald) Connect() {
|
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)
|
crash(err)
|
||||||
s.socket = socket
|
s.socket = socket
|
||||||
log.Print("Connected to signald socket ", socket.RemoteAddr().String())
|
log.Print("Connected to signald socket ", socket.RemoteAddr().String())
|
||||||
|
|
Loading…
Reference in a new issue