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, _) => {
|
||||
let re_carriage_returns = REGEXES.carriage_returns();
|
||||
let re_chkdsk_splits = REGEXES.chkdsk_splits();
|
||||
let output_text = if stderr.is_empty() {
|
||||
stdout.clone()
|
||||
} else {
|
||||
format!("{stdout}\n\n-------\n\n{stderr}")
|
||||
};
|
||||
let parsed_lines: Vec<String> = 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 output_text = remove_carriage_returns(&output_text);
|
||||
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();
|
||||
|
||||
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() {
|
||||
// stdout.to_string()
|
||||
// } else {
|
||||
// format!("{stdout}\n\n --stderr-- \n\n{stderr}")
|
||||
// };
|
||||
// // TODO: Implement actual logic for result
|
||||
// Log {
|
||||
// label: String::from("CHKDSK"),
|
||||
// raw,
|
||||
// summary,
|
||||
// }
|
||||
// // 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")
|
||||
}
|
||||
|
||||
pub fn remove_carriage_returns(text: &str) -> String {
|
||||
let re_carriage_returns = REGEXES.carriage_returns();
|
||||
let parsed_lines: Vec<String> = 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();
|
||||
parsed_lines.join("\n")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue