From d4b7bcd28e0d22d2ca52295e3c20437d642c1625 Mon Sep 17 00:00:00 2001 From: DewaldV Date: Fri, 19 Apr 2024 14:28:13 +0100 Subject: [PATCH] Inital bits for batch --- Cargo.lock | 23 +++++++++++++++++++++++ Cargo.toml | 2 ++ src/batch.rs | 12 ++++++++++++ src/error.rs | 10 ++++++++++ src/main.rs | 19 ++++++++++++++++++- 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/batch.rs create mode 100644 src/error.rs diff --git a/Cargo.lock b/Cargo.lock index 9251ad9..6a623a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -220,6 +220,27 @@ version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" +[[package]] +name = "csv" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" +dependencies = [ + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" +dependencies = [ + "memchr", +] + [[package]] name = "encoding_rs" version = "0.8.34" @@ -266,7 +287,9 @@ version = "0.1.0" dependencies = [ "chrono", "clap", + "csv", "monzo-lib", + "thiserror", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index a75df41..09b23d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,9 @@ license = "MIT" [dependencies] chrono = "0.4.37" clap = { version = "4.5.3", features = ["derive", "env"] } +csv = "1.3.0" # monzo-lib = "0.4.4" monzo-lib = { git = "https://github.com/DewaldV/monzo-lib.git" } +thiserror = "1.0.58" # monzo-lib = { path = "../monzo-lib" } tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/src/batch.rs b/src/batch.rs new file mode 100644 index 0000000..6d4c154 --- /dev/null +++ b/src/batch.rs @@ -0,0 +1,12 @@ +use std::{fs::File, path::Path}; + +use crate::error::Result; + +pub async fn run(_token: String, file: String) -> Result<()> { + let path = Path::new(&file); + println!("batch file path: {}", path.display()); + + let _batch_file = File::open(&path)?; + + Ok(()) +} diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..9c310fa --- /dev/null +++ b/src/error.rs @@ -0,0 +1,10 @@ +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[error("Monzo API error: {0}")] + MonzoAPI(#[from] monzo::Error), + + #[error("IO error: {0}")] + IO(#[from] std::io::Error), +} + +pub type Result = std::result::Result; diff --git a/src/main.rs b/src/main.rs index 1c3b6f3..383fa79 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,10 @@ use clap::{Parser, Subcommand}; +use error::Result; mod accounts; +mod batch; mod currency; +mod error; mod pots; mod transactions; @@ -22,6 +25,10 @@ enum Commands { #[command(subcommand)] acc_cmd: AccountCommands, }, + Batch { + #[command(subcommand)] + batch_cmd: BatchCommands, + }, Pots { #[command(subcommand)] pot_cmd: PotsCommands, @@ -37,6 +44,11 @@ enum AccountCommands { List, } +#[derive(Subcommand)] +enum BatchCommands { + Run { file: String }, +} + #[derive(Subcommand)] enum PotsCommands { List { name: Option }, @@ -55,7 +67,7 @@ enum TransactionCommands { } #[tokio::main] -async fn main() -> monzo::Result<()> { +async fn main() -> Result<()> { let args = CLI::parse(); match args.cmd { @@ -64,6 +76,11 @@ async fn main() -> monzo::Result<()> { accounts::list(&args.monzo_access_token).await?; } }, + Commands::Batch { batch_cmd } => match batch_cmd { + BatchCommands::Run { file } => { + batch::run(args.monzo_access_token, file).await?; + } + }, Commands::Pots { pot_cmd } => match pot_cmd { PotsCommands::List { name: _ } => { pots::list(&args.monzo_access_token).await?;