aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: bed2ce171d3e16293d82418ffbd8ede7412a091c (plain)
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
mod db;
mod deck;
mod gui;
mod model;
mod space_repetition;
mod util;

use crate::util::event::Events;
use anyhow::Result;
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(StructOpt)]
#[structopt()]
struct Opt {
    #[structopt(long, default_value = "deck.deck")]
    deck: String,
}

fn main() -> Result<()> {
    let deck_path = Opt::from_args().deck;
    let conn = db::init(db_path(&deck_path))?;
    let deck_name = deck::pp_from_path(&deck_path).unwrap_or_else(|| "Deck".to_string());
    let mut term = gui::terminal()?;
    let events = Events::new();
    gui::synchronize(&conn, &mut term, &events, &deck_path, &deck_name)?;
    gui::start(&conn, &mut term, &events, &deck_name)
}

fn db_path(deck_path: &str) -> String {
    let mut path = PathBuf::from(deck_path);
    path.set_extension("db");
    path.to_string_lossy().to_string()
}