From f615981064c6e496229185b46880014943433385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 3 Aug 2021 20:46:42 +0200 Subject: lib.rs --- cli/src/lib.rs | 3 ++ cli/src/main.rs | 87 ++++++++++++++++++++++++++------------------------------- 2 files changed, 43 insertions(+), 47 deletions(-) create mode 100644 cli/src/lib.rs diff --git a/cli/src/lib.rs b/cli/src/lib.rs new file mode 100644 index 0000000..24ed014 --- /dev/null +++ b/cli/src/lib.rs @@ -0,0 +1,3 @@ +pub mod search; +pub mod store; +pub mod transaction; diff --git a/cli/src/main.rs b/cli/src/main.rs index 7b5f9e2..a01ee94 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,4 +1,7 @@ -use chrono::naive::NaiveDate; +use chrono::NaiveDate; +use money_cli::search::{Search, parse_filters}; +use money_cli::store::Store; +use money_cli::transaction::{Transaction, TransactionKind}; use rust_decimal::Decimal; use std::cmp::Ordering; use std::path::PathBuf; @@ -7,19 +10,40 @@ use structopt::clap::AppSettings; use structopt::StructOpt; use tabled::{Style, Table}; -mod search; -mod store; -mod transaction; +#[derive(Debug)] +#[derive(StructOpt)] +pub enum SortTarget { + Amount, + Date, +} -use search::Search; -use store::Store; -use transaction::{Transaction, TransactionKind}; +impl std::str::FromStr for SortTarget { + type Err = String; -use crate::search::parse_filters; + fn from_str(s: &str) -> Result { + match s { + "amount" => Ok(SortTarget::Amount), + "date" => Ok(SortTarget::Date), + _ => Err(format!("Unknown sort target: {:?}", s)), + } + } +} -//TODO relative ("yesterday", "-2d", etc) -fn parse_date(s: &str) -> Result { - NaiveDate::parse_from_str(s, "%Y-%m-%d").map_err(|e| e.to_string()) +#[derive(Debug)] +#[derive(StructOpt)] +pub enum ListTarget { + Categories, +} + +impl std::str::FromStr for ListTarget { + type Err = String; + + fn from_str(s: &str) -> Result { + match s { + "categories" => Ok(ListTarget::Categories), + _ => Err(format!("Unknown listable: {:?}", s)), + } + } } #[derive(Debug)] @@ -53,42 +77,6 @@ enum Command { }, } -#[derive(Debug)] -#[derive(StructOpt)] -enum ListTarget { - Categories, -} - -impl std::str::FromStr for ListTarget { - type Err = String; - - fn from_str(s: &str) -> Result { - match s { - "categories" => Ok(ListTarget::Categories), - _ => Err(format!("Unknown listable: {:?}", s)), - } - } -} - -#[derive(Debug)] -#[derive(StructOpt)] -enum SortTarget { - Amount, - Date, -} - -impl std::str::FromStr for SortTarget { - type Err = String; - - fn from_str(s: &str) -> Result { - match s { - "amount" => Ok(SortTarget::Amount), - "date" => Ok(SortTarget::Date), - _ => Err(format!("Unknown sort target: {:?}", s)), - } - } -} - #[derive(Debug)] #[derive(StructOpt)] struct Mn { @@ -164,3 +152,8 @@ fn sort_by_func(sort: &SortTarget) -> impl FnMut(&&Transaction, &&Transaction) - SortTarget::Date => |t1: &&Transaction, t2: &&Transaction| t1.date.cmp(&t2.date), } } + +//TODO relative ("yesterday", "-2d", etc) +pub fn parse_date(s: &str) -> Result { + NaiveDate::parse_from_str(s, "%Y-%m-%d").map_err(|e| e.to_string()) +} -- cgit v1.2.1