From 72ca2bc14c41bab69944dc943d908a4ea3d1f8c2 Mon Sep 17 00:00:00 2001 From: alemidev Date: Sat, 25 Jun 2022 02:59:00 +0200 Subject: [PATCH] feat: allow to pass specific db file via argv --- src/main.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3dc94e4..38ca5e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,19 +6,33 @@ use crate::app::{ worker::{BackgroundWorker, NativeBackgroundWorker}, App, }; +use std::path::PathBuf; use std::sync::Arc; +use tracing::metadata::LevelFilter; use tracing_subscriber::prelude::*; // When compiling natively: #[cfg(not(target_arch = "wasm32"))] fn main() -> ! { - use tracing::metadata::LevelFilter; - let native_options = eframe::NativeOptions::default(); - let mut store_path = dirs::data_dir().unwrap_or(std::path::PathBuf::from(".")); // TODO get cwd more consistently? + let args: Vec = std::env::args().collect(); + + // Set default file location + let mut store_path = dirs::data_dir().unwrap_or(PathBuf::from(".")); // TODO get cwd more consistently? store_path.push("dashboard.db"); + // Can be overruled from argv + for (index, arg) in args.iter().enumerate() { + if index <= 0 || arg.eq("--") { + continue; + } + store_path = PathBuf::from(arg.as_str()); + break; + } + + println!("path: {}", store_path.to_str().unwrap()); + let store = Arc::new(ApplicationState::new(store_path).expect("Failed creating application state"));