diff --git a/cmd/signaldctl/cmd/message/send/send-message.go b/cmd/signaldctl/cmd/message/send/send-message.go index e4f705e..81b4f44 100644 --- a/cmd/signaldctl/cmd/message/send/send-message.go +++ b/cmd/signaldctl/cmd/message/send/send-message.go @@ -18,6 +18,7 @@ package send import ( "encoding/json" "fmt" + "io/ioutil" "log" "os" "path/filepath" @@ -37,9 +38,10 @@ var ( toAddress *v1.JsonAddress toGroup string attachments []string + message string SendMessageCmd = &cobra.Command{ - Use: "send ", + Use: "send {group id | phone number} [message]", Short: "send a message", PreRun: func(cmd *cobra.Command, args []string) { if account == "" { @@ -49,9 +51,20 @@ var ( common.Must(cmd.Help()) log.Fatal("No account specified. Please specify with --account or set a default") } - if len(args) < 2 { + if len(args) < 1 { common.Must(cmd.Help()) - log.Fatal("must specify both destination (either group id or phone number) and message") + log.Fatal("must specify both destination (either group id or phone number)") + } + + if len(args) == 1 { + messageBytes, err := ioutil.ReadAll(os.Stdin) + if err != nil { + log.Println("error reading message from stdin, perhaps you meant to include it in the command line arguments?") + panic(err) + } + message = string(messageBytes) + } else { + message = strings.Join(args[1:], " ") } to, err := common.StringToAddress(args[0]) if err != nil { @@ -65,7 +78,7 @@ var ( req := v1.SendRequest{ Username: account, - MessageBody: strings.Join(args[1:], " "), + MessageBody: message, Attachments: []*v1.JsonAttachment{}, RecipientAddress: toAddress, RecipientGroupID: toGroup,