pub mod patterns;
use std::collections::HashMap;
#[derive(Default)]
pub struct CorrectionDetector {
history: Vec<(String, i32)>, pub corrections: HashMap<String, String>,
}
impl CorrectionDetector {
pub fn record(&mut self, command: &str, exit_code: i32) {
self.history.push((command.to_string(), exit_code));
self.detect();
}
fn detect(&mut self) {
let len = self.history.len();
if len >= 2 {
let prev = &self.history[len - 2];
let curr = &self.history[len - 1];
if prev.0 == curr.0 && prev.1 != 0 && curr.1 != 0 {
self.corrections
.entry(curr.0.clone())
.or_insert_with(|| format!("check usage of `{}`", curr.0));
}
}
}
}