add stream -json
parent
b6d4c40dd6
commit
e7f2469bc0
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
@ -12,6 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func cmdStream(c *cli.Context) error {
|
||||
asJSON := c.Bool("json")
|
||||
client := c.App.Metadata["client"].(*mastodon.Client)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
@ -27,6 +29,9 @@ func cmdStream(c *cli.Context) error {
|
|||
close(q)
|
||||
}()
|
||||
for e := range q {
|
||||
if asJSON {
|
||||
json.NewEncoder(c.App.Writer).Encode(e)
|
||||
} else {
|
||||
switch t := e.(type) {
|
||||
case *mastodon.UpdateEvent:
|
||||
color.Set(color.FgHiRed)
|
||||
|
@ -39,5 +44,6 @@ func cmdStream(c *cli.Context) error {
|
|||
color.Set(color.Reset)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -180,6 +180,12 @@ func makeApp() *cli.App {
|
|||
{
|
||||
Name: "stream",
|
||||
Usage: "stream statuses",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "json",
|
||||
Usage: "output JSON",
|
||||
},
|
||||
},
|
||||
Action: cmdStream,
|
||||
},
|
||||
{
|
||||
|
|
|
@ -14,7 +14,9 @@ import (
|
|||
)
|
||||
|
||||
// UpdateEvent is struct for passing status event to app.
|
||||
type UpdateEvent struct{ Status *Status }
|
||||
type UpdateEvent struct {
|
||||
Status *Status `json:"status"`
|
||||
}
|
||||
|
||||
func (e *UpdateEvent) event() {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue