aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
blob: d53ce1c9410fb32792fa86afffabca14640812c5 (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
mod app;
mod paths;
mod views;
mod ynab;

use snafu::ResultExt;

#[derive(Debug, snafu::Snafu)]
pub enum Error {
    #[snafu(display("failed to get api key: {}", source))]
    GetApiKey { source: crate::paths::Error },

    #[snafu(display("failed to load budget: {}", source))]
    LoadBudget { source: crate::ynab::BudgetError },
}

pub type Result<T> = std::result::Result<T, Error>;

fn run() -> Result<()> {
    let key = paths::read_api_key().context(GetApiKey)?;
    let budget = ynab::Budget::new(&key).context(LoadBudget)?;

    let mut app = app::App::new(budget);
    app.run();

    Ok(())
}

fn main() {
    match run() {
        Ok(_) => {}
        Err(e) => {
            eprintln!("ynab-reimbursements: {}", e);
            std::process::exit(1);
        }
    }
}