summaryrefslogtreecommitdiffstats
path: root/cli/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src/main.rs')
-rw-r--r--cli/src/main.rs63
1 files changed, 53 insertions, 10 deletions
diff --git a/cli/src/main.rs b/cli/src/main.rs
index 9c6edb6..606d3c1 100644
--- a/cli/src/main.rs
+++ b/cli/src/main.rs
@@ -1,18 +1,61 @@
+use rust_decimal::Decimal;
use std::path::PathBuf;
+use std::str::FromStr;
+use structopt::StructOpt;
mod model;
+#[derive(Debug)]
+#[derive(StructOpt)]
+enum Command {
+ Insert {
+ kind: model::TransactionKind,
+ #[structopt(long)]
+ account: String,
+
+ // #[structopt(long = "category", multiple = true, number_of_values = 1)]
+ // category: Vec<String>,
+ #[structopt(long)]
+ category: String,
+
+ #[structopt(long, parse(try_from_str = Decimal::from_str))]
+ amount: Decimal,
+
+ description: String,
+ },
+}
+
+#[derive(Debug)]
+#[derive(StructOpt)]
+struct Mn {
+ #[structopt(subcommand)]
+ command: Command,
+}
+
+// mn insert expense --account Kortkonto --category a --category b
+
fn main() {
- // let post = Post::new(Transaction {
- // description: "Test".to_string(),
- // category: "Mat".to_string(),
- // amount: Decimal::try_from(120.4_f64).unwrap(),
- // kind: TransactionKind::Expense,
- // from: "Kortkonto".to_string(),
- // to: "Coop Lambohov".to_string(),
- // });
+ match Mn::from_args().command {
+ Command::Insert {
+ kind,
+ account,
+ category,
+ amount,
+ description,
+ } => {
+ let post = model::Post::new(model::Transaction {
+ kind,
+ to: account,
+ from: "Default".to_string(),
+ category,
+ amount,
+ description
+ });
+ println!("{:?}", post);
+ }
+ }
// post.write(&"test").unwrap();
- let store = model::Store::open(PathBuf::from("store")).unwrap();
+ // let store = model::Store::open(PathBuf::from("store")).unwrap();
// println!("{:#?}", store);
- store.write().unwrap();
+ // store.write().unwrap();
}