add stream -simplejson
parent
0579b31633
commit
eb0803d442
|
@ -12,8 +12,15 @@ import (
|
|||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
type SimpleJSON struct {
|
||||
Username string `json:"username"`
|
||||
Avatar string `json:"avatar"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
func cmdStream(c *cli.Context) error {
|
||||
asJSON := c.Bool("json")
|
||||
asSimpleJSON := c.Bool("simplejson")
|
||||
client := c.App.Metadata["client"].(*mastodon.Client)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
@ -31,6 +38,14 @@ func cmdStream(c *cli.Context) error {
|
|||
for e := range q {
|
||||
if asJSON {
|
||||
json.NewEncoder(c.App.Writer).Encode(e)
|
||||
} else if asSimpleJSON {
|
||||
if t, ok := e.(*mastodon.UpdateEvent); ok {
|
||||
json.NewEncoder(c.App.Writer).Encode(&SimpleJSON{
|
||||
Username: t.Status.Account.Username,
|
||||
Avatar: t.Status.Account.AvatarStatic,
|
||||
Content: textContent(t.Status.Content),
|
||||
})
|
||||
}
|
||||
} else {
|
||||
switch t := e.(type) {
|
||||
case *mastodon.UpdateEvent:
|
||||
|
|
|
@ -185,6 +185,10 @@ func makeApp() *cli.App {
|
|||
Name: "json",
|
||||
Usage: "output JSON",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "simplejson",
|
||||
Usage: "output simple JSON",
|
||||
},
|
||||
},
|
||||
Action: cmdStream,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue