-
Notifications
You must be signed in to change notification settings - Fork 9
Add CommandExt
for working with std::process::Command
output streams
#535
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
Conversation
ce52b7f
to
c4be703
Compare
Command
outputCommandExt
for working with std::process::Command
output streams
605177d
to
4e483c1
Compare
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.
Still working on the review. Wanted to leave these questions/notes for you. I'll pick up the write.rs and finish up later.
Overall looks good. I like having some of this general purpose goodness in shared libraries.
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.
Added some additional comments.
- One question about whether we need Clone or why we might not want it.
- Another comment related to naming. I would like to add
capture
tooutput_and_write_streams
or otherwise indicate what it's doing as I feel the existing naming ofspawn
oroutput
isn't very descriptive. I would prefer it but don't want to block on it if you feel strongly otherwise.
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.
Thank you for adding this!
While working on the Gradle buildpack, I had the need to prefix
gradlew
output so the user can clearly distinguish betweengradlew
and buildpack output. While implementing a solution, @dzuelke mentioned that he has the same need and also some additional ones. So I went the extra mile, made my solution generic and added docs so that it is easy to use. Implementing this is less trivial than it might sound so I thought it's a great fit forlibherokubuildpack
(or whatever it will be called in the future)It all revolves around a new trait:
CommandExt
which extendsstd::process:Command
with (currently) two helpers that allow writing the unbuffered output ofstdout
andstderr
to astd::io::Writer
.This is the main hook to add more complex logic like
tee
ing output to two different locations, prefixing lines and live-modifying streams using standardString
functions. These helpers are contained in the newwrite
module which has the aforementioned helpers. These can be used withoutCommentExt
and are standalone. Their only interface isstd::io::Write
.Here is an example how this can be used:
The exposed API has proper rust docstrings. For detailed info and more usage examples refer to those.
Closes GUS-W-12188139