Move carriage return removal to its own function
Pretty sure I'll need it elsewhere
This commit is contained in:
parent
92dcfc2592
commit
0084b5968d
1 changed files with 14 additions and 38 deletions
|
|
@ -149,22 +149,15 @@ pub fn parse_chkdsk(diag_group: &mut DiagGroup, task_result: TaskResult) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
TaskResult::Output(stdout, stderr, _) => {
|
TaskResult::Output(stdout, stderr, _) => {
|
||||||
let re_carriage_returns = REGEXES.carriage_returns();
|
|
||||||
let re_chkdsk_splits = REGEXES.chkdsk_splits();
|
let re_chkdsk_splits = REGEXES.chkdsk_splits();
|
||||||
let output_text = if stderr.is_empty() {
|
let output_text = if stderr.is_empty() {
|
||||||
stdout.clone()
|
stdout.clone()
|
||||||
} else {
|
} else {
|
||||||
format!("{stdout}\n\n-------\n\n{stderr}")
|
format!("{stdout}\n\n-------\n\n{stderr}")
|
||||||
};
|
};
|
||||||
let parsed_lines: Vec<String> = output_text
|
let output_text = remove_carriage_returns(&output_text);
|
||||||
.split("\r\n")
|
|
||||||
.filter_map(|line| {
|
|
||||||
let line = re_carriage_returns.replace_all(line, "").trim().to_string();
|
|
||||||
if line.is_empty() { None } else { Some(line) }
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
let parsed_output = re_chkdsk_splits
|
let parsed_output = re_chkdsk_splits
|
||||||
.replace_all(parsed_lines.join("\n").as_str(), "\n $1")
|
.replace_all(output_text.as_str(), "\n $1")
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
if parsed_output.contains("Windows has scanned the file system and found no problems.")
|
if parsed_output.contains("Windows has scanned the file system and found no problems.")
|
||||||
|
|
@ -193,33 +186,16 @@ pub fn parse_chkdsk(diag_group: &mut DiagGroup, task_result: TaskResult) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// let mut summary = Vec::new();
|
|
||||||
// let raw = if stderr.is_empty() {
|
pub fn remove_carriage_returns(text: &str) -> String {
|
||||||
// stdout.to_string()
|
let re_carriage_returns = REGEXES.carriage_returns();
|
||||||
// } else {
|
let parsed_lines: Vec<String> = text
|
||||||
// format!("{stdout}\n\n --stderr-- \n\n{stderr}")
|
.split("\r\n")
|
||||||
// };
|
.filter_map(|line| {
|
||||||
// // TODO: Implement actual logic for result
|
let line = re_carriage_returns.replace_all(line, "").trim().to_string();
|
||||||
// Log {
|
if line.is_empty() { None } else { Some(line) }
|
||||||
// label: String::from("CHKDSK"),
|
})
|
||||||
// raw,
|
.collect();
|
||||||
// summary,
|
parsed_lines.join("\n")
|
||||||
// }
|
|
||||||
// // Split lines
|
|
||||||
// let lines: Vec<_> = output.split("\r\n").collect();
|
|
||||||
//
|
|
||||||
// // Omit progress lines and unhelpful messages
|
|
||||||
// lines
|
|
||||||
// .into_iter()
|
|
||||||
// .filter(|line| {
|
|
||||||
// !(line.contains("\r")
|
|
||||||
// || line.contains("Class not registered")
|
|
||||||
// || line.contains("/F parameter")
|
|
||||||
// || line.contains("Running CHKDSK")
|
|
||||||
// || line.contains("Total duration:")
|
|
||||||
// || line.contains("Failed to transfer logged messages"))
|
|
||||||
// })
|
|
||||||
// .collect::<Vec<_>>()
|
|
||||||
// .join("\n")
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue