From eb0803d442d49224fde531b61ee4e73bd20df5af Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 17 Apr 2017 23:43:11 +0900 Subject: [PATCH] add stream -simplejson --- cmd/mstdn/cmd_stream.go | 15 +++++++++++++++ cmd/mstdn/main.go | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/cmd/mstdn/cmd_stream.go b/cmd/mstdn/cmd_stream.go index b7122f3..1ba9a6c 100644 --- a/cmd/mstdn/cmd_stream.go +++ b/cmd/mstdn/cmd_stream.go @@ -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: diff --git a/cmd/mstdn/main.go b/cmd/mstdn/main.go index 0e2cb4e..e24586a 100644 --- a/cmd/mstdn/main.go +++ b/cmd/mstdn/main.go @@ -185,6 +185,10 @@ func makeApp() *cli.App { Name: "json", Usage: "output JSON", }, + cli.BoolFlag{ + Name: "simplejson", + Usage: "output simple JSON", + }, }, Action: cmdStream, },