Skip to content

Commit

Permalink
feat: Allow to override data path with BIRTHDAY_DATA environment vari…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
ducdetronquito committed Jan 14, 2024
1 parent 7acfe29 commit 0ee4e2d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/birthday_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ pub fn add(name: String, date: String) -> Result<()> {
}

fn get_db_path() -> Result<PathBuf> {
let mut data_dir = match ProjectDirs::from("", "", "birthday") {
Some(project_dirs) => project_dirs.data_dir().to_owned(),
None => Path::new("./").to_owned(),
let mut data_dir = match std::env::var("BIRTHDAY_DATA") {
Ok(path) => PathBuf::from(path),
Err(_) => match ProjectDirs::from("", "", "birthday") {
Some(project_dirs) => project_dirs.data_dir().to_owned(),
None => Path::new("./").to_owned(),
},
};

std::fs::create_dir_all(&data_dir)?;
data_dir.push("test.db");
Ok(data_dir)
Expand Down

0 comments on commit 0ee4e2d

Please sign in to comment.