Improve debug implementation of `Command`
In normal mode `Debug` now prints just the command-line (similarly to `std::process::Command`). This is useful for logging commands and formatting error messages that includes command-line. In "alternate" mode full internals of this structure are still printed.
This commit is contained in:
parent
fa4ab47e97
commit
378b8ac11a
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