Merge pull request #18 from tailhook/better_debug
Improve debug implementation of `Command`
This commit is contained in:
commit
c8bdbc1de6
21
src/lib.rs
21
src/lib.rs
|
@ -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<()> {
|
||||
|
|
Loading…
Reference in New Issue