diff options
Diffstat (limited to 'cli/src/main.rs')
| -rw-r--r-- | cli/src/main.rs | 87 |
1 files changed, 40 insertions, 47 deletions
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<Self, Self::Err> { + 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, String> { - 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<Self, Self::Err> { + match s { + "categories" => Ok(ListTarget::Categories), + _ => Err(format!("Unknown listable: {:?}", s)), + } + } } #[derive(Debug)] @@ -55,42 +79,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<Self, Self::Err> { - 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<Self, Self::Err> { - match s { - "amount" => Ok(SortTarget::Amount), - "date" => Ok(SortTarget::Date), - _ => Err(format!("Unknown sort target: {:?}", s)), - } - } -} - -#[derive(Debug)] -#[derive(StructOpt)] struct Mn { #[structopt(subcommand)] command: Command, @@ -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, String> { + NaiveDate::parse_from_str(s, "%Y-%m-%d").map_err(|e| e.to_string()) +} |
