Skip to content

Commit

Permalink
Merge pull request #13 from Konippi/refactor/how-to-build-path-in-reader
Browse files Browse the repository at this point in the history
refactor: how to build path in reader
  • Loading branch information
kenkoooo authored Aug 14, 2024
2 parents a5d8949 + 9f66a85 commit a7daf01
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ use std::{env, fs, path::PathBuf};

/// Read seeds from specified file
pub fn read_file(filename: &str, base_dir: &str) -> Result<String> {
let mut path = PathBuf::new();
if let Ok(current_base) = env::var("CARGO_MANIFEST_DIR") {
path.push(current_base)
}
path.push(base_dir);
path.push(filename);
let path = env::var("CARGO_MANIFEST_DIR")
.map(PathBuf::from)
.unwrap_or_default()
.join(base_dir)
.join(filename);

fs::read_to_string(&path)
.map_err(|err| anyhow::anyhow!("Can't open the file: {:?}\n err: {}", path, err))
Expand Down

0 comments on commit a7daf01

Please sign in to comment.