diff options
author | Joris | 2022-02-06 19:47:09 +0100 |
---|---|---|
committer | Joris | 2022-02-06 19:47:09 +0100 |
commit | 3b6ceec4c5425d2741af7bff1fdad385f04e250f (patch) | |
tree | bd20cd863779aca8dee6c351916bfd5d32ba0e19 | |
parent | 37f646c9908e0ebb5077874fcd0e93b1bbde0694 (diff) |
Ask only for the deck path
Derive the DB path from the deck path.
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | src/main.rs | 18 |
2 files changed, 12 insertions, 9 deletions
@@ -1,3 +1,2 @@ target/ -deck -database.db +deck* 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() +} |