use - instatt of --stdin to detect stdin

This commit is contained in:
Martin/Geno 2019-07-26 08:53:33 +02:00 committed by Mickaël Rémond
parent ff5885f29d
commit 5697d40e5c
2 changed files with 5 additions and 15 deletions

View File

@ -27,7 +27,6 @@ Flags:
--jid string using jid (required) --jid string using jid (required)
-m, --muc reciever is a muc (join it before sending messages) -m, --muc reciever is a muc (join it before sending messages)
--password string using password for your jid (required) --password string using password for your jid (required)
-i, --stdin read from stdin instatt of 2. argument
``` ```
@ -47,7 +46,7 @@ $ sendxmpp to@example.org "Hello Welt"
Message from STDIN: Message from STDIN:
```bash ```bash
$ journalctl -f | sendxmpp to@example.org --stdin $ journalctl -f | sendxmpp to@example.org -
info client connected info client connected
⇢ cmd.go:56 main.glob..func1.1 ⇢ cmd.go:56 main.glob..func1.1
⇢ 2019-07-17T23:40:03.177+02:00 ⇢ 2019-07-17T23:40:03.177+02:00
@ -81,7 +80,7 @@ $ sendxmpp to1@example.org,to2@example.org "Multiple reciever"
Send to MUC: Send to MUC:
```bash ```bash
journalctl -f | sendxmpp testit@conference.chat.sum7.eu --stdin --muc journalctl -f | sendxmpp testit@conference.chat.sum7.eu - --muc
info client connected info client connected
⇢ cmd.go:56 main.glob..func1.1 ⇢ cmd.go:56 main.glob..func1.1
⇢ 2019-07-17T23:52:56.269+02:00 ⇢ 2019-07-17T23:52:56.269+02:00

View File

@ -19,22 +19,14 @@ var jid = ""
var password = "" var password = ""
var receiverMUC = false var receiverMUC = false
var stdIn = false
var cmd = &cobra.Command{ var cmd = &cobra.Command{
Use: "sendxmpp <recieve,> [message]", Use: "sendxmpp <recieve,> [message]",
Example: `sendxmpp to@chat.sum7.eu "Hello World!"`, Example: `sendxmpp to@chat.sum7.eu "Hello World!"`,
Args: cobra.RangeArgs(1, 2), Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
receiver := strings.Split(args[0], ",") receiver := strings.Split(args[0], ",")
msgText := "" msgText := args[1]
if !stdIn && len(args) < 2 {
log.Error("no message to send")
return
} else if !stdIn {
msgText = args[1]
}
var err error var err error
client, err := xmpp.NewClient(xmpp.Config{ client, err := xmpp.NewClient(xmpp.Config{
@ -62,7 +54,7 @@ var cmd = &cobra.Command{
} }
} }
if !stdIn { if msgText != "-" {
send(c, receiver, msgText) send(c, receiver, msgText)
return return
} }
@ -101,7 +93,6 @@ func init() {
cmd.Flags().StringP("addr", "", "", "host[:port]") cmd.Flags().StringP("addr", "", "", "host[:port]")
viper.BindPFlag("addr", cmd.Flags().Lookup("addr")) viper.BindPFlag("addr", cmd.Flags().Lookup("addr"))
cmd.Flags().BoolVarP(&stdIn, "stdin", "i", false, "read from stdin instatt of 2. argument")
cmd.Flags().BoolVarP(&receiverMUC, "muc", "m", false, "reciever is a muc (join it before sending messages)") cmd.Flags().BoolVarP(&receiverMUC, "muc", "m", false, "reciever is a muc (join it before sending messages)")
} }