diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 27 |
1 files changed, 13 insertions, 14 deletions
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(()) |