-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLI and API command output encoding #215
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for implementing this, it's been bugging me for a while... And thanks for making it possible to incrementally switch over, that'll make this much easier to land.
Sorry for the very slow response, things that touch this library tend to be scary so I tend to procrastinate. This looks quite reasonable, so I'll be sure to make future review cycles shorter. |
No worries whatsoever. Thanks very much for the review. |
Following the approach described in ipfs#115, define a new method signature on `Command` that supports full processing of the `Response` object when text encoding is requested. Add an encoding check and dispatch to DisplayCLI in local, http client, and http handler code paths. Unblocks resolution of `encoding` option processing in multiple go-ipfs issues. - ipfs/kubo#7050 json encoding for `ls` - ipfs/kubo#1121 json encoding for `add` - ipfs/kubo#5594 json encoding for `stats bw`
979b1bd
to
9e5e502
Compare
- When both PostRun (output transformer) and DisplayCLI (terminal output) are present, ensure that both are run. `EmitResponse` helper in executor.go is invoked by both local and HTTP client executors: the client fibs the command.Run interface via anonymous function.
9e5e502
to
11083f0
Compare
Sorry for the conflicts (;´∀`)
I'll try not to create any more trouble ;^) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved conflicts. ✨
It seems #215 (comment) the only remaining question / concern – @jbouwman mind taking a look at @Stebalien's question?
Close the channel immediately if it will never be used.
@lidel sure thing, done. @Stebalien does that look right, in terms of order of error checks? |
Yes. But I missed the other thing. |
I had cycles to look at this again. The cli.ResponseEmitter wrapper for DisplayCLI seems a little odd -- its main role seems to be in allowing PostRun-enabled commands access to process exit value via a cast. I didn't see a less invasive way to do it though. I'd welcome your thoughts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me think about this a bit.
stdout io.Writer | ||
stderr io.Writer | ||
|
||
re cmds.ResponseEmitter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can embed this instead of manually forwarding.
go func() { | ||
err := req.Command.DisplayCLI(res, os.Stdout, os.Stderr) | ||
if err != nil { | ||
dre.CloseWithError(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. This isn't going to work:
- The caller will send an error to
dre
viaCloseWithError
. DisplayCLI
will get this error fromres
, and return it.- We're then going to feed it back into
dre
here.
Really, we need to expose this error via some method and/or a channel. I'll try to think of the right approach.
func (dre *displayResponseEmitter) SetLength(l uint64) { | ||
dre.re.SetLength(l) | ||
} | ||
|
||
func (dre *displayResponseEmitter) SetStatus(code int) { | ||
dre.l.Lock() | ||
defer dre.l.Unlock() | ||
dre.exit = code | ||
} | ||
|
||
func (dre *displayResponseEmitter) Status() int { | ||
dre.l.Lock() | ||
defer dre.l.Unlock() | ||
return dre.exit | ||
} | ||
|
||
func (dre *displayResponseEmitter) Stderr() io.Writer { | ||
return dre.stderr | ||
} | ||
|
||
func (dre *displayResponseEmitter) Stdout() io.Writer { | ||
return dre.stdout | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can actually just drop these methods from the interface. But it'll require some investigation.
@Stebalien : what are the recommended next steps? Is this high enough priority for us to engage on right now? |
@jbouwman : it looks like there are some comments from @Stebalien that you can incorporate (but I see there are open questions too). @Stebalien : are you able to give definitive on what should be done here, or should we drop this for now due to not having bandwidth to engage? |
@jbouwman : I have converted this back to draft. Please mark it as "Ready for review" when comments have been incorporated. |
I just don't have the bandwidth right now, unfortunately. |
Following the approach described in #115, define a new method signature on
Command
that supports full processing of theResponse
object when text encoding is requested.Add an encoding check and dispatch to DisplayCLI in local, http client, and http handler code paths.
Unblocks resolution of
encoding
option processing in multiple go-ipfs issues.ipfs --encoding=json ls
not returning JSON kubo#7050 json encoding forls
add
ipfs stats bw
doesn't support --enc json kubo#5594 json encoding forstats bw
Closes #115