diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-07-30 14:32:58 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-07-30 14:32:58 +0200 |
| commit | eb22945b21de880c294bb91bf0e8c1bb5a9e63d0 (patch) | |
| tree | d72f4600a2f79cb413d7026f883c8f485bdc293f /cli/src/main.rs | |
| parent | 2349b42a13dc6cabf92b53d370245281b73c5395 (diff) | |
| download | money-eb22945b21de880c294bb91bf0e8c1bb5a9e63d0.tar.gz | |
additive/subtractive filters and date filters
Diffstat (limited to 'cli/src/main.rs')
| -rw-r--r-- | cli/src/main.rs | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs index d1e793d..6b8da59 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,7 +1,8 @@ -use chrono::{naive::NaiveDate, Duration}; +use chrono::naive::NaiveDate; use rust_decimal::Decimal; use std::path::PathBuf; use std::str::FromStr; +use structopt::clap::AppSettings; use structopt::StructOpt; use tabled::{Style, Table}; @@ -9,7 +10,7 @@ mod search; mod store; mod transaction; -use search::{Constraint, DateFilter, Search}; +use search::Search; use store::Store; use transaction::{Transaction, TransactionKind}; @@ -41,7 +42,10 @@ enum Command { List { target: ListTarget, }, - Show, + #[structopt(setting = AppSettings::AllowLeadingHyphen)] + Show { + filters: Vec<String>, + }, } #[derive(Debug)] @@ -71,12 +75,11 @@ struct Mn { fn main() { let mut store = Store::open(PathBuf::from("store")).unwrap(); - let search = Search::new(store.transactions()); // let search = search.subtract(Constraint::Category("a".to_string())); - let search = search.subtract(Constraint::Date(DateFilter::Relative { - start: None, - end: Some(Duration::days(-2)), - })); + // let search = search.subtract(Constraint::Date(DateFilter::Relative { + // start: None, + // end: Some(Duration::days(-2)), + // })); let args = Mn::from_args(); eprintln!("{:?}", args); @@ -111,7 +114,13 @@ fn main() { } => { println!("{}", store.categories().join("\n")); } - Command::Show => { + Command::Show { + filters + } => { + let mut search = Search::new(store.transactions()); + if !filters.is_empty() { + search = search.parse(filters.join(" ")); + } let mut transactions = search.get(); transactions.sort_by(|t1, t2| t1.date.cmp(&t2.date)); println!("{}", Table::new(transactions).with(Style::psql())); |
