Skip to content

Commit

Permalink
Pin LS command emits custom JSON to handle streaming case
Browse files Browse the repository at this point in the history
  • Loading branch information
aschmahmann committed Oct 7, 2019
1 parent f1cd629 commit 69bb578
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"context"
"encoding/json"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -367,6 +368,17 @@ Example:
},
Type: &PinLsOutputWrapper{},
Encoders: cmds.EncoderMap{
cmds.JSON: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *PinLsOutputWrapper) error {
stream, _ := req.Options[pinStreamOptionName].(bool)

enc := json.NewEncoder(w)

if stream {
return enc.Encode(out.PinLsObject)
}

return enc.Encode(out.PinLsList)
}),
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *PinLsOutputWrapper) error {
quiet, _ := req.Options[pinQuietOptionName].(bool)
stream, _ := req.Options[pinStreamOptionName].(bool)
Expand Down

0 comments on commit 69bb578

Please sign in to comment.