mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-08-07 21:47:11 +00:00
system report: factor out getting command output into helper fn
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
3b5cb8fd33
commit
c55884d1a7
@ -148,6 +148,19 @@ fn get_directory_content(path: impl AsRef<Path>) -> String {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_command_output(exe: &str, args: &Vec<&str>) -> String {
|
||||||
|
let output = Command::new(exe)
|
||||||
|
.env("PROXMOX_OUTPUT_NO_BORDER", "1")
|
||||||
|
.args(args)
|
||||||
|
.output();
|
||||||
|
let output = match output {
|
||||||
|
Ok(output) => String::from_utf8_lossy(&output.stdout).to_string(),
|
||||||
|
Err(err) => err.to_string(),
|
||||||
|
};
|
||||||
|
let output = output.trim_end();
|
||||||
|
format!("$ `{exe} {}`\n```\n{output}\n```", args.join(" "))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn generate_report() -> String {
|
pub fn generate_report() -> String {
|
||||||
let file_contents = files()
|
let file_contents = files()
|
||||||
.iter()
|
.iter()
|
||||||
@ -173,18 +186,7 @@ pub fn generate_report() -> String {
|
|||||||
|
|
||||||
let command_outputs = commands()
|
let command_outputs = commands()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(command, args)| {
|
.map(|(command, args)| get_command_output(command, args))
|
||||||
let output = Command::new(command)
|
|
||||||
.env("PROXMOX_OUTPUT_NO_BORDER", "1")
|
|
||||||
.args(args)
|
|
||||||
.output();
|
|
||||||
let output = match output {
|
|
||||||
Ok(output) => String::from_utf8_lossy(&output.stdout).to_string(),
|
|
||||||
Err(err) => err.to_string(),
|
|
||||||
};
|
|
||||||
let output = output.trim_end();
|
|
||||||
format!("$ `{command} {}`\n```\n{output}\n```", args.join(" "))
|
|
||||||
})
|
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
.join("\n\n");
|
.join("\n\n");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user