Add flag --command to the stream command
If --command is set to the path of an executable file, it will be run
for each event and the output be be sent to the standard input.
The --output or --theme options can still be used.
--- a/cmd/stream.go Tue May 09 20:14:28 2017 +0200
+++ b/cmd/stream.go Tue May 09 20:14:28 2017 +0200
@@ -16,11 +16,9 @@
"github.com/McKael/madon"
)
-/*
var streamOpts struct {
- local bool
+ command string
}
-*/
// Maximum number of websockets (1 hashtag <=> 1 ws)
const maximumHashtagStreamWS = 4
@@ -52,7 +50,7 @@
func init() {
RootCmd.AddCommand(streamCmd)
- //streamCmd.Flags().BoolVar(&streamOpts.local, "local", false, "Events from the local instance")
+ streamCmd.Flags().StringVar(&streamOpts.command, "command", "", "Execute external command")
}
func streamRunE(cmd *cobra.Command, args []string) error {
@@ -155,6 +153,9 @@
os.Exit(1)
}
+ // Set up external command
+ p.setCommand(streamOpts.command)
+
LISTEN:
for {
select {
@@ -176,11 +177,15 @@
errPrint("Event: [%s]", ev.Event)
case "update":
s := ev.Data.(madon.Status)
- p.printObj(&s)
+ if err = p.printObj(&s); err != nil {
+ break LISTEN
+ }
continue
case "notification":
n := ev.Data.(madon.Notification)
- p.printObj(&n)
+ if p.printObj(&n); err != nil {
+ break LISTEN
+ }
continue
case "delete":
// TODO PrintObj ?
@@ -192,5 +197,9 @@
}
close(stop)
close(evChan)
+ if err != nil {
+ errPrint("Error: %s", err.Error())
+ os.Exit(1)
+ }
return nil
}