diff options
author | Adam T. Carpenter <atc@53hor.net> | 2021-04-15 20:03:01 -0400 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2021-04-15 20:03:01 -0400 |
commit | d83fe68ed51016bbb87d83aa512ef8b9d3f0780e (patch) | |
tree | 05f93d34464692c706288f7bb3497f55e4539b09 /src/repo | |
parent | 93d9a3b8d6984a8f113a30fea523607162e71589 (diff) | |
download | twinh-d83fe68ed51016bbb87d83aa512ef8b9d3f0780e.tar.xz twinh-d83fe68ed51016bbb87d83aa512ef8b9d3f0780e.zip |
split config into modules that actually need it, started parsing args
Diffstat (limited to 'src/repo')
-rw-r--r-- | src/repo/mod.rs | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/repo/mod.rs b/src/repo/mod.rs index 45e9ce3..c7992c9 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -1,4 +1,3 @@ -use crate::config::CONFIG_INSTANCE; use crate::error::TwinHError; use crate::models::Car; use crate::models::Part; @@ -6,20 +5,28 @@ use bincode::deserialize; use constants::*; use once_cell::sync::Lazy; use sled::{Config, Db}; +use std::env; mod constants; -static REPO_INSTANCE: Lazy<Db> = Lazy::new(|| { - Config::default() - .path(&CONFIG_INSTANCE.db_path) - .temporary(true) - .open() - .expect("Couldn't open DB!") +pub static DB_PATH_INSTANCE: Lazy<String> = Lazy::new(|| { + env::args() + .skip(1) + .last() + .expect("database directory not provided") }); +static REPO_INSTANCE: Lazy<Db> = + Lazy::new( + || match Config::default().path(DB_PATH_INSTANCE.as_str()).open() { + Err(e) => panic!("failed to open database: {}", e), + Ok(db) => db, + }, + ); + pub fn create_demo_db() -> Result<(), TwinHError> { let db = sled::Config::default() - .path(&CONFIG_INSTANCE.db_path) + .path(DB_PATH_INSTANCE.as_str()) .create_new(true) .open()?; let cars_tree = db.open_tree(CARS_TREE)?; @@ -28,7 +35,7 @@ pub fn create_demo_db() -> Result<(), TwinHError> { pub fn create_new_db() -> Result<(), TwinHError> { sled::Config::default() - .path(&CONFIG_INSTANCE.db_path) + .path(DB_PATH_INSTANCE.as_str()) .create_new(true) .open()?; Ok(()) |