1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::process::Command;
pub trait CommandInfo {
fn info(&self) -> String;
fn multiline_info(&self, chars_per_line: usize) -> String;
}
impl CommandInfo for Command {
fn info(&self) -> String {
let program = self.get_program().to_string_lossy();
let args = self
.get_args()
.map(|arg| arg.to_string_lossy())
.collect::<Vec<_>>()
.join(" ");
format!("{program} {args}")
}
fn multiline_info(&self, chars_per_line: usize) -> String {
let info = self.info();
if info.len() > chars_per_line {
let program = self.get_program().to_string_lossy();
let args = self
.get_args()
.map(|arg| arg.to_string_lossy())
.collect::<Vec<_>>()
.join(" \\\n")
.replace(" \\\n-", " -");
format!("{program} {args}")
} else {
info
}
}
}