summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-08-03 20:46:42 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-08-03 20:46:42 +0200
commitf615981064c6e496229185b46880014943433385 (patch)
tree1823d69a47b74de57ff75691936b7957cfce6345
parentc1ae0dd77fa210508383c2b813adb9ae3ccf2742 (diff)
downloadmoney-f615981064c6e496229185b46880014943433385.tar.gz
lib.rs
-rw-r--r--cli/src/lib.rs3
-rw-r--r--cli/src/main.rs87
2 files changed, 43 insertions, 47 deletions
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<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())
+}