From 8af0034ae0bb7a4067abd296f9f27f9aafd18a82 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Sun, 14 Feb 2021 16:53:18 +0000 Subject: Neaten the history listing code (#5) I'd like to reduce the amount of SQL in the database code. Make it as generic as possible, and later on perhaps expose a generic "execute" function. This function can be used by analysis commands, and the SQL can live there - rather than database.rs being a huge bag of SQL. --- src/command/history.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/command/history.rs') diff --git a/src/command/history.rs b/src/command/history.rs index 73be66fa..5959fc55 100644 --- a/src/command/history.rs +++ b/src/command/history.rs @@ -34,6 +34,12 @@ pub enum Cmd { }, } +fn print_list(h: &Vec) { + for i in h { + println!("{}", i.command); + } +} + impl Cmd { pub fn run(&self, db: &mut Sqlite) -> Result<()> { match self { @@ -68,7 +74,12 @@ impl Cmd { Ok(()) } - Self::List { distinct } => db.list(*distinct), + Self::List { .. } => { + let history = db.list()?; + print_list(&history); + + Ok(()) + } } } } -- cgit v1.3.1