diff options
author | jvech <jmvalenciae@unal.edu.co> | 2024-04-28 22:53:50 -0500 |
---|---|---|
committer | jvech <jmvalenciae@unal.edu.co> | 2024-04-28 22:53:50 -0500 |
commit | a361eb833f516befe79b45a8b6ed3162a21bc06a (patch) | |
tree | 71c2228f2159e09351c778076354c872a1a8d433 /src/main.rs | |
parent | ac7bcafae3b9cdb75a9df35a9ab8e37adb1eb192 (diff) |
add: view subcommand implemented
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(()) |