Merge pull request #18 from tailhook/better_debug

Improve debug implementation of `Command`
This commit is contained in:
Taiki Endo 2021-10-11 23:22:26 +09:00 committed by GitHub
commit c8bdbc1de6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 1 deletions

View File

@ -616,7 +616,6 @@ impl io::AsyncRead for ChildStderr {
/// };
/// # std::io::Result::Ok(()) });
/// ```
#[derive(Debug)]
pub struct Command {
inner: std::process::Command,
stdin: Option<Stdio>,
@ -940,6 +939,26 @@ impl Command {
}
}
impl fmt::Debug for Command {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.alternate() {
f.debug_struct("Command")
.field("inner", &self.inner)
.field("stdin", &self.stdin)
.field("stdout", &self.stdout)
.field("stderr", &self.stderr)
.field("reap_on_drop", &self.reap_on_drop)
.field("kill_on_drop", &self.kill_on_drop)
.finish()
} else {
// Stdlib outputs command-line in Debug for Command. This does the
// same, if not in "alternate" (long pretty-printed) mode.
// This is useful for logs, for example.
fmt::Debug::fmt(&self.inner, f)
}
}
}
/// Moves `Fd` out of non-blocking mode.
#[cfg(unix)]
fn blocking_fd(fd: std::os::unix::io::RawFd) -> io::Result<()> {