diff --git a/cmd/signald-cli/cmd/root.go b/cmd/signald-cli/cmd/root.go index de24eb8..a943e55 100644 --- a/cmd/signald-cli/cmd/root.go +++ b/cmd/signald-cli/cmd/root.go @@ -17,6 +17,7 @@ package cmd import ( "fmt" + "log" "os" "github.com/spf13/cobra" @@ -50,7 +51,11 @@ func init() { RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.signald-cli.yaml)") 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() + err := s.Connect() + if err != nil { + log.Fatal(err) + } + } // initConfig reads in config file and ENV variables if set. diff --git a/cmd/signald-cli/cmd/send.go b/cmd/signald-cli/cmd/send.go index dbba3d7..a6132bd 100644 --- a/cmd/signald-cli/cmd/send.go +++ b/cmd/signald-cli/cmd/send.go @@ -19,6 +19,7 @@ import ( "log" "github.com/spf13/cobra" + "time" "git.callpipe.com/finn/signald-go/signald" "git.callpipe.com/finn/signald-go/signald/client-protocol/v1" @@ -59,6 +60,20 @@ var sendCmd = &cobra.Command{ request.AttachmentFilenames = []string{attachment} } s.SendRequest(request) + + timeout := 10 + + // Wait for the response + c := make(chan signald.Response) + + go s.Listen(c) + select { + case <-c: + log.Println("Ok.") + case <-time.After(1 * time.Second): + // But timeout after a while + log.Fatalf("Timeout after %d seconds\n", timeout) + } }, } diff --git a/signald/client-protocol/v1/types.go b/signald/client-protocol/v1/types.go index 18929c0..70596d8 100644 --- a/signald/client-protocol/v1/types.go +++ b/signald/client-protocol/v1/types.go @@ -2,7 +2,7 @@ package v1 // JsonAddress is a signal user's contact information. a phone number, UUID or both type JsonAddress struct { - UUID string `json:"uuid"` + UUID string `json:"uuid,omitempty"` Number string `json:"number"` } @@ -26,7 +26,7 @@ type JsonReadMessage struct { type JsonSendMessageResult struct { Address JsonAddress `json:"address"` - Success Success `json:"success"` + Success Success `json:"success"` NetworkFailure bool `json:"networkFailure"` UnregisteredFailure bool `json:"unregisteredFailure"` IdentityFailure string `json:"identityFailure"`