diff options
author | Joris | 2022-01-26 14:31:42 +0100 |
---|---|---|
committer | Joris | 2022-01-26 14:31:42 +0100 |
commit | fe0d0196f133bd902b176aa02119b7f2a49ebc35 (patch) | |
tree | 64411c7054041e822bd28ffc7debbc3ad6840111 /src | |
parent | b743fc24ec3ba1aa3ff9bfe5c802019e90034312 (diff) |
Read database path from arguments
Diffstat (limited to 'src')
-rw-r--r-- | src/db/db.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 11 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/db/db.rs b/src/db/db.rs index a3398e2..86614ec 100644 --- a/src/db/db.rs +++ b/src/db/db.rs @@ -9,8 +9,8 @@ use rusqlite::{params, Connection}; use rusqlite_migration::{Migrations, M}; use std::time::SystemTime; -pub fn init() -> Result<Connection> { - let mut conn = Connection::open("database.db")?; +pub fn init(database: String) -> Result<Connection> { + let mut conn = Connection::open(database)?; let migrations = Migrations::new(vec![M::up(include_str!("sql/1-init.sql"))]); migrations.to_latest(&mut conn)?; Ok(conn) diff --git a/src/main.rs b/src/main.rs index 4761366..ef47c73 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,18 @@ mod space_repetition; mod util; use anyhow::Result; +use structopt::StructOpt; + +#[derive(StructOpt)] +#[structopt()] +struct Opt { + #[structopt(short, long, default_value = "database.db")] + database: String, +} fn main() -> Result<()> { - let conn = db::db::init()?; + let opt = Opt::from_args(); + let conn = db::db::init(opt.database)?; let entries = deck::read()?; db::db::add_missing_deck_entries(&conn, entries)?; gui::gui::start(&conn) |