From f206de5d49eda1900552a4b19f01c8c6985b7903 Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Wed, 28 Apr 2021 19:58:27 -0400 Subject: finally committed to structopt arg parsing --- src/repo/mod.rs | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'src/repo') diff --git a/src/repo/mod.rs b/src/repo/mod.rs index c7992c9..80b2814 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -1,32 +1,23 @@ +use crate::config; use crate::error::TwinHError; use crate::models::Car; use crate::models::Part; use bincode::deserialize; use constants::*; -use once_cell::sync::Lazy; use sled::{Config, Db}; -use std::env; mod constants; -pub static DB_PATH_INSTANCE: Lazy = Lazy::new(|| { - env::args() - .skip(1) - .last() - .expect("database directory not provided") -}); - -static REPO_INSTANCE: Lazy = - Lazy::new( - || match Config::default().path(DB_PATH_INSTANCE.as_str()).open() { - Err(e) => panic!("failed to open database: {}", e), - Ok(db) => db, - }, - ); +lazy_static! { + static ref REPO_INSTANCE: Db = match Config::default().path(&config::INSTANCE.data_dir).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(DB_PATH_INSTANCE.as_str()) + .path(&config::INSTANCE.data_dir) .create_new(true) .open()?; let cars_tree = db.open_tree(CARS_TREE)?; @@ -35,7 +26,7 @@ pub fn create_demo_db() -> Result<(), TwinHError> { pub fn create_new_db() -> Result<(), TwinHError> { sled::Config::default() - .path(DB_PATH_INSTANCE.as_str()) + .path(&config::INSTANCE.data_dir) .create_new(true) .open()?; Ok(()) -- cgit v1.2.3