bricks/cli/
commandext.rs

1use std::process::Command;
2
3pub trait CommandExt {
4    /// Transforms a Command to a string representation
5    /// ```
6    /// use bricks::cli::commandext::CommandExt;
7    /// let mut cmd = std::process::Command::new("ls");
8    /// cmd.arg("-al").arg(".");
9    /// assert_eq!(cmd.to_string(), "ls -al .".to_string());
10    /// ```
11    fn to_string(&self) -> String;
12}
13
14impl CommandExt for Command {
15    fn to_string(&self) -> String {
16        format!(
17            "{} {}",
18            self.get_program().to_string_lossy(),
19            self.get_args()
20                .map(|arg| arg.to_string_lossy())
21                .collect::<Vec<_>>()
22                .join(" ")
23        )
24    }
25}