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
40
41
42
43
44
45
use std::ffi::OsStr;
use std::ffi::OsString;
use std::path::Path;

use tracing::trace;

use crate::Cmd;

pub trait CommandDebug {
	fn debug(&mut self) -> &mut Self;
}

impl CommandDebug for std::process::Command {
	fn debug(&mut self) -> &mut Self {
		let path = Path::new(self.get_program());
		let s = self.get_args().fold(vec![], |mut a: Vec<&OsStr>, b: &OsStr| {
			a.push(b);
			a
		});
		trace!(
			"Executing `{} {}`...",
			path.file_name().unwrap().to_str().unwrap(),
			s.join(OsString::from(" ").as_os_str()).to_str().unwrap().trim()
		);
		self
	}
}

impl CommandDebug for Cmd {
	fn debug(&mut self) -> &mut Self {
		let path = Path::new(self.program.as_os_str());
		let s = (&self.args)
			.into_iter()
			.fold(Vec::new(), |mut a: Vec<OsString>, b: &OsString| {
				a.push(b.clone());
				a
			});
		trace!(
			"Executing `{} {}`...",
			path.file_name().unwrap().to_str().unwrap(),
			s.join(OsString::from(" ").as_os_str()).to_str().unwrap().trim()
		);
		self
	}
}