@cryptotaxi247 / kubo / commits / 69bb57895

Pin LS command emits custom JSON to handle streaming case

Adin Schmahmann committed Oct 7, 2019 at 08:27 UTC 69bb57895a851b0a559d7f948d0442594e91a643
1 file changed +12
core/commands/pin.go
+12
@@ -2,6 +2,7 @@ package commands
2
3 import (
4 "context"
5 + "encoding/json"
6 "fmt"
7 "io"
8 "os"
@@ -367,6 +368,17 @@ Example:
368 },
369 Type: &PinLsOutputWrapper{},
370 Encoders: cmds.EncoderMap{
371 + cmds.JSON: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *PinLsOutputWrapper) error {
372 + stream, _ := req.Options[pinStreamOptionName].(bool)
373 +
374 + enc := json.NewEncoder(w)
375 +
376 + if stream {
377 + return enc.Encode(out.PinLsObject)
378 + }
379 +
380 + return enc.Encode(out.PinLsList)
381 + }),
382 cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *PinLsOutputWrapper) error {
383 quiet, _ := req.Options[pinQuietOptionName].(bool)
384 stream, _ := req.Options[pinStreamOptionName].(bool)