From a361eb833f516befe79b45a8b6ed3162a21bc06a Mon Sep 17 00:00:00 2001 From: jvech Date: Sun, 28 Apr 2024 22:53:50 -0500 Subject: add: view subcommand implemented --- src/main.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 8ef62b3..be23ac3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,26 +22,25 @@ fn main() -> Result<()> { } }, Commands::Register {person, amount, note, payment} => { - let register = Database::new(person, amount, note, !payment); - if let Some(datapath) = cli.database_path { - register.add_register(&datapath)?; - } else { - panic!("database file not found"); - } + let register = Database::new(person, amount as i32, note, !payment); + let datapath = cli.database_path.unwrap(); + register.add_register(&datapath)?; }, Commands::View {history, filter, total} => { - println!("{}", filter.unwrap_or(String::from("None"))); - println!("{}", history); - println!("{}", total); + let datapath = cli.database_path.expect("database path not found"); + + match (history, total) { + (true, false) => Database::view_history(&datapath, filter)?, + (false, true) => Database::view_total(&datapath)?, + (false, false) => Database::view_total(&datapath)?, + (true, true) => unreachable!() + } }, Commands::Add {name} => { let register = Database::new(name, 0, None, false); - if let Some(datapath) = cli.database_path { - register.add_agent(&datapath)?; - } else { - panic!("database file not found"); - } + let datapath = cli.database_path.unwrap(); + register.add_agent(&datapath)?; } }; Ok(()) -- cgit v1.2.3-70-g09d2