Skip to content

Commit

Permalink
Inital bits for batch
Browse files Browse the repository at this point in the history
  • Loading branch information
DewaldV committed Apr 19, 2024
1 parent f78b1a2 commit d4b7bcd
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
12 changes: 12 additions & 0 deletions src/batch.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
10 changes: 10 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -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<T> = std::result::Result<T, Error>;
19 changes: 18 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use clap::{Parser, Subcommand};
use error::Result;

mod accounts;
mod batch;
mod currency;
mod error;
mod pots;
mod transactions;

Expand All @@ -22,6 +25,10 @@ enum Commands {
#[command(subcommand)]
acc_cmd: AccountCommands,
},
Batch {
#[command(subcommand)]
batch_cmd: BatchCommands,
},
Pots {
#[command(subcommand)]
pot_cmd: PotsCommands,
Expand All @@ -37,6 +44,11 @@ enum AccountCommands {
List,
}

#[derive(Subcommand)]
enum BatchCommands {
Run { file: String },
}

#[derive(Subcommand)]
enum PotsCommands {
List { name: Option<String> },
Expand All @@ -55,7 +67,7 @@ enum TransactionCommands {
}

#[tokio::main]
async fn main() -> monzo::Result<()> {
async fn main() -> Result<()> {
let args = CLI::parse();

match args.cmd {
Expand All @@ -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?;
Expand Down

0 comments on commit d4b7bcd

Please sign in to comment.