aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorjvech <jmvalenciae@unal.edu.co>2024-04-23 07:52:28 -0500
committerjvech <jmvalenciae@unal.edu.co>2024-04-23 07:52:28 -0500
commita5dfd2627853bd67e9d17ef870fc84be312b1397 (patch)
tree85e005be5e96916f2d45d85a703ff2717ed28c51 /src/main.rs
add: first commit done
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..8ef62b3
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,48 @@
+use xdg;
+use rusqlite::Result;
+
+mod database;
+mod cli;
+
+use cli::{Cli, Commands};
+use crate::database::Database;
+
+fn main() -> Result<()> {
+ let cli = Cli::new();
+ match cli.action {
+ Commands::Init => {
+ if let Some(datapath) = cli.database_path {
+ Database::init_database(&datapath)?;
+ } else {
+ let datapath = xdg::BaseDirectories::with_prefix("debt")
+ .expect("xdg file setup failed")
+ .place_data_file("cache.db")
+ .expect("xdg directory creaton failed");
+ Database::init_database(&datapath)?;
+ }
+ },
+ 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");
+ }
+ },
+ Commands::View {history, filter, total} => {
+ println!("{}", filter.unwrap_or(String::from("None")));
+ println!("{}", history);
+ println!("{}", total);
+ },
+
+ 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");
+ }
+ }
+ };
+ Ok(())
+}
Feel free to download, copy and edit any repo