summaryrefslogtreecommitdiffstats
path: root/cli/src/main.rs
blob: a76040116acdceaf5acc541926152d37f123591a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 mut store = model::Store::open(PathBuf::from("store")).unwrap();
    println!("{:?}", store);
    match Mn::from_args().command {
        Command::Insert {
            kind,
            account,
            category,
            amount,
            description,
        } => {
            let transaction = model::Transaction {
                kind,
                to: account,
                from: "Default".to_string(),
                category,
                amount,
                description
            };
            println!("{:?}", transaction);
            store.push(transaction);
            store.write().unwrap();
        }
    }
}