From 68285db2c187b350bb2b1707071382bd9fbaa2a5 Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 26 Feb 2022 22:42:25 +0100 Subject: Give database path from argument --- src/db/mod.rs | 4 ++-- src/gui/mod.rs | 3 ++- src/main.rs | 11 ++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/db/mod.rs b/src/db/mod.rs index b27226b..1bbf21e 100644 --- a/src/db/mod.rs +++ b/src/db/mod.rs @@ -6,8 +6,8 @@ use uuid::Uuid; use crate::model::event::Event; -pub fn init() -> Result { - let mut conn = Connection::open("database.db")?; +pub fn init(db_path: &str) -> Result { + let mut conn = Connection::open(db_path)?; let migrations = Migrations::new(vec![M::up(include_str!("migrations/1-init.sql"))]); migrations.to_latest(&mut conn)?; Ok(conn) diff --git a/src/gui/mod.rs b/src/gui/mod.rs index a8a025c..c33500b 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -18,7 +18,8 @@ pub fn run(conn: Connection) { let app = gtk::Application::new(Some("me.guyonvarch.calendar"), Default::default()); app.connect_startup(|_| load_style()); app.connect_activate(move |app| build_ui(conn.clone(), app)); - app.run(); + let args: [&str; 0] = []; + app.run_with_args(&args); } fn build_ui(conn: Rc, app: >k::Application) { diff --git a/src/main.rs b/src/main.rs index 8999a52..956e930 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,9 +3,18 @@ mod gui; mod model; use anyhow::Result; +use structopt::StructOpt; + +#[derive(StructOpt)] +#[structopt()] +struct Opt { + #[structopt(long, default_value = "database.db")] + database: String, +} fn main() -> Result<()> { - let conn = db::init()?; + let db_path = Opt::from_args().database; + let conn = db::init(&db_path)?; gui::run(conn); Ok(()) } -- cgit v1.2.3