1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
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) }