equal
deleted
inserted
replaced
14 "github.com/spf13/cobra" |
14 "github.com/spf13/cobra" |
15 |
15 |
16 "github.com/McKael/madon" |
16 "github.com/McKael/madon" |
17 ) |
17 ) |
18 |
18 |
19 /* |
|
20 var streamOpts struct { |
19 var streamOpts struct { |
21 local bool |
20 command string |
22 } |
21 } |
23 */ |
|
24 |
22 |
25 // Maximum number of websockets (1 hashtag <=> 1 ws) |
23 // Maximum number of websockets (1 hashtag <=> 1 ws) |
26 const maximumHashtagStreamWS = 4 |
24 const maximumHashtagStreamWS = 4 |
27 |
25 |
28 // streamCmd represents the stream command |
26 // streamCmd represents the stream command |
50 } |
48 } |
51 |
49 |
52 func init() { |
50 func init() { |
53 RootCmd.AddCommand(streamCmd) |
51 RootCmd.AddCommand(streamCmd) |
54 |
52 |
55 //streamCmd.Flags().BoolVar(&streamOpts.local, "local", false, "Events from the local instance") |
53 streamCmd.Flags().StringVar(&streamOpts.command, "command", "", "Execute external command") |
56 } |
54 } |
57 |
55 |
58 func streamRunE(cmd *cobra.Command, args []string) error { |
56 func streamRunE(cmd *cobra.Command, args []string) error { |
59 streamName := "user" |
57 streamName := "user" |
60 tag := "" |
58 tag := "" |
153 close(evChan) |
151 close(evChan) |
154 errPrint("Error: %s", err.Error()) |
152 errPrint("Error: %s", err.Error()) |
155 os.Exit(1) |
153 os.Exit(1) |
156 } |
154 } |
157 |
155 |
|
156 // Set up external command |
|
157 p.setCommand(streamOpts.command) |
|
158 |
158 LISTEN: |
159 LISTEN: |
159 for { |
160 for { |
160 select { |
161 select { |
161 case v, ok := <-done: |
162 case v, ok := <-done: |
162 if !ok || v == true { // done is closed, end of streaming |
163 if !ok || v == true { // done is closed, end of streaming |
174 continue |
175 continue |
175 } |
176 } |
176 errPrint("Event: [%s]", ev.Event) |
177 errPrint("Event: [%s]", ev.Event) |
177 case "update": |
178 case "update": |
178 s := ev.Data.(madon.Status) |
179 s := ev.Data.(madon.Status) |
179 p.printObj(&s) |
180 if err = p.printObj(&s); err != nil { |
|
181 break LISTEN |
|
182 } |
180 continue |
183 continue |
181 case "notification": |
184 case "notification": |
182 n := ev.Data.(madon.Notification) |
185 n := ev.Data.(madon.Notification) |
183 p.printObj(&n) |
186 if p.printObj(&n); err != nil { |
|
187 break LISTEN |
|
188 } |
184 continue |
189 continue |
185 case "delete": |
190 case "delete": |
186 // TODO PrintObj ? |
191 // TODO PrintObj ? |
187 errPrint("Event: [%s] Status %d was deleted", ev.Event, ev.Data.(int64)) |
192 errPrint("Event: [%s] Status %d was deleted", ev.Event, ev.Data.(int64)) |
188 default: |
193 default: |
190 } |
195 } |
191 } |
196 } |
192 } |
197 } |
193 close(stop) |
198 close(stop) |
194 close(evChan) |
199 close(evChan) |
|
200 if err != nil { |
|
201 errPrint("Error: %s", err.Error()) |
|
202 os.Exit(1) |
|
203 } |
195 return nil |
204 return nil |
196 } |
205 } |