Skip to content

Commit

Permalink
revert local encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwman committed Sep 8, 2021
1 parent 957684f commit 16f14e9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
21 changes: 0 additions & 21 deletions executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package cmds

import (
"context"
"io"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -35,25 +33,6 @@ type executor struct {
root *Command
}

// GetLocalEncoder provides special treatment for text encoding
// when Command.DisplayCLI field is non-nil, by defining an
// Encoder that delegates to a nested emitter that consumes a Response
// and writes to the underlying io.Writer using DisplayCLI.
func GetLocalEncoder(req *Request, w io.Writer, def EncodingType) (EncodingType, Encoder, error) {
encType, enc, err := GetEncoder(req, w, def)
if err != nil {
return encType, nil, err
}

if req.Command.DisplayCLI != nil && encType == Text {
emitter, response := NewChanResponsePair(req)
go req.Command.DisplayCLI(response, w, ioutil.Discard)
return encType, &emitterEncoder{emitter: emitter}, nil
}

return encType, enc, nil
}

type emitterEncoder struct {
emitter ResponseEmitter
}
Expand Down
2 changes: 1 addition & 1 deletion http/responseemitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (

// NewResponseEmitter returns a new ResponseEmitter.
func NewResponseEmitter(w http.ResponseWriter, method string, req *cmds.Request, opts ...ResponseEmitterOption) (ResponseEmitter, error) {
encType, enc, err := cmds.GetLocalEncoder(req, w, cmds.JSON)
encType, enc, err := cmds.GetEncoder(req, w, cmds.JSON)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 16f14e9

Please sign in to comment.