summaryrefslogtreecommitdiff
path: root/src/repo
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2021-04-28 19:58:27 -0400
committerAdam T. Carpenter <atc@53hor.net>2021-04-28 19:58:27 -0400
commitf206de5d49eda1900552a4b19f01c8c6985b7903 (patch)
tree86f0b681e01eeda4a8d5f03a85c988866538b981 /src/repo
parentd83fe68ed51016bbb87d83aa512ef8b9d3f0780e (diff)
downloadtwinh-f206de5d49eda1900552a4b19f01c8c6985b7903.tar.xz
twinh-f206de5d49eda1900552a4b19f01c8c6985b7903.zip
finally committed to structopt arg parsingenhancement/2
Diffstat (limited to 'src/repo')
-rw-r--r--src/repo/mod.rs27
1 files changed, 9 insertions, 18 deletions
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<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,
- },
- );
+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(())