use super::errors::*;
use super::{Command, History, Settings};
use log::error;
impl History {
pub fn new(limit: usize, pattern: &str) -> Self {
History {
commands: get_commands(limit, pattern).unwrap(),
}
}
pub fn show(&self) {
self.commands.iter().for_each(|command| command.show())
}
}
fn get_commands(limit: usize, _pattern: &str) -> Result<Vec<Command>> {
let settings = Settings::default();
let command_paths = settings.command_log_paths(limit, "*")?;
let mut commands = Vec::new();
for path in command_paths {
match Command::load(&path) {
Ok(c) => commands.push(c),
Err(e) => {
error!(target: "reef","error loading {:?}\n{}", &path, e);
}
}
}
Ok(commands)
}