diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2016-12-05 19:02:05 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2016-12-06 23:45:45 +0100 |
| commit | db4fc5acc9278d13af9b8439953c43394289351d (patch) | |
| tree | 0a06964f271a4b84be3664b56dcecbe98783af55 /src | |
| parent | 91380810eafb1fc8e4ce7cc8c2b6f326cd2bb4f4 (diff) | |
| download | mullvadvpn-db4fc5acc9278d13af9b8439953c43394289351d.tar.xz mullvadvpn-db4fc5acc9278d13af9b8439953c43394289351d.zip | |
Implement Display for OpenVpnBuilder
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; |
