summaryrefslogtreecommitdiffstats
path: root/cli/src/main.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-07-29 13:09:48 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-07-29 13:17:09 +0200
commitf0dbf13ab231bfc913571487ae9394214a70f7b9 (patch)
treebfb3cc38e65e999e73b2a1a56bc0b9c7bb31cc0e /cli/src/main.rs
parentccda716764ae84dee9f18f66e383b66c9e30b3b9 (diff)
downloadmoney-f0dbf13ab231bfc913571487ae9394214a70f7b9.tar.gz
date
Diffstat (limited to 'cli/src/main.rs')
-rw-r--r--cli/src/main.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs
index 6de8dbd..5a77ff4 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -1,3 +1,4 @@
+use chrono::naive::NaiveDate;
use rust_decimal::Decimal;
use std::path::PathBuf;
use std::str::FromStr;
@@ -5,6 +6,10 @@ use structopt::StructOpt;
mod model;
+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)]
enum Command {
@@ -22,6 +27,8 @@ enum Command {
amount: Decimal,
description: String,
+ #[structopt(long, parse(try_from_str = parse_date))]
+ date: Option<NaiveDate>,
},
List {
target: ListTarget,
@@ -57,7 +64,7 @@ struct Mn {
fn main() {
let mut store = model::Store::open(PathBuf::from("store")).unwrap();
let args = Mn::from_args();
- println!("{:?}", args);
+ eprintln!("{:?}", args);
match args.command {
Command::Insert {
kind,
@@ -65,6 +72,7 @@ fn main() {
category,
amount,
description,
+ date,
} => {
let transaction = model::Transaction {
kind,
@@ -72,9 +80,14 @@ fn main() {
from: "Default".to_string(),
category,
amount,
- description
+ description,
+ date: match date {
+ Some(date) => date,
+ None => chrono::offset::Local::today().naive_utc(),
+ },
};
- println!("{:?}", transaction);
+ eprintln!("{:?}", transaction);
+ println!("{}", transaction.id());
store.push(transaction);
store.write().unwrap();
}