diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2016-12-07 14:32:18 +0100 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2016-12-07 14:32:18 +0100 |
| commit | 03d3693b6b33990b583468afcd9568678ab15268 (patch) | |
| tree | aef3464d1db8c9f81841112617acf9104cdf30eb /src/process.rs | |
| parent | 876441779e8bdb64abe7822969a822db81f5c7ac (diff) | |
| parent | 6d8e98afb08d067b98616d5c7f9ebe3570fdc838 (diff) | |
| download | mullvadvpn-03d3693b6b33990b583468afcd9568678ab15268.tar.xz mullvadvpn-03d3693b6b33990b583468afcd9568678ab15268.zip | |
Merge branch 'add-convenience'
Diffstat (limited to 'src/process.rs')
| -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; |
