From 3b6ceec4c5425d2741af7bff1fdad385f04e250f Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 6 Feb 2022 19:47:09 +0100 Subject: Ask only for the deck path Derive the DB path from the deck path. --- src/main.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index f9d2288..9720370 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,21 +7,25 @@ mod util; use anyhow::Result; use structopt::StructOpt; +use std::path::PathBuf; #[derive(StructOpt)] #[structopt()] struct Opt { - #[structopt(long, default_value = "database.db")] - database: String, - - #[structopt(long, default_value = "deck.deck")] + #[structopt(long, default_value = "deck")] deck: String, } fn main() -> Result<()> { - let opt = Opt::from_args(); - let conn = db::db::init(opt.database)?; - let entries = deck::read(opt.deck)?; + let deck = Opt::from_args().deck; + let conn = db::db::init(db_path(&deck))?; + let entries = deck::read(deck)?; db::db::synchronize(&conn, entries)?; gui::gui::start(&conn) } + +fn db_path(deck_path: &String) -> String { + let mut path = PathBuf::from(deck_path); + path.set_extension("db"); + path.to_string_lossy().to_string() +} -- cgit v1.2.3