diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/process.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/process.rs b/src/process.rs index eb372de04e..b350517b2a 100644 --- a/src/process.rs +++ b/src/process.rs @@ -1,6 +1,7 @@ use net::RemoteAddr; use std::ffi::{OsString, OsStr}; +use std::fmt; use std::io; use std::path::{Path, PathBuf}; use std::process::{Command, Child, Stdio}; @@ -69,6 +70,31 @@ impl OpenVpnBuilder { } } +impl fmt::Display for OpenVpnBuilder { + /// Format the program and arguments of an `OpenVpnBuilder` for display. Any non-utf8 data is + /// lossily converted using the utf8 replacement character. + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt.write_str(&self.openvpn_bin.to_string_lossy())?; + for arg in self.get_arguments().iter().map(|arg| arg.to_string_lossy()) { + write_argument(fmt, &arg)?; + } + Ok(()) + } +} + +fn write_argument(fmt: &mut fmt::Formatter, arg: &str) -> fmt::Result { + fmt.write_str(" ")?; + let quote = arg.contains(char::is_whitespace); + if quote { + fmt.write_str("\"")?; + } + fmt.write_str(&arg)?; + if quote { + fmt.write_str("\"")?; + } + Ok(()) +} + #[cfg(test)] mod tests { use net::RemoteAddr; |
