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

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 = Opt::from_args().deck;
    let conn = db::db::init(db_path(&deck))?;
    let entries = deck::read(&deck)?;
    db::db::synchronize(&conn, entries)?;
    let deck_name = deck::pp_from_path(&deck).unwrap_or("Deck".to_string());
    gui::gui::start(&conn, &deck_name)
}

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