Skip to content

Commit 243be66

Browse files
committed
Read settings.toml from CWD cf. model dir
Closes #513.
1 parent f175309 commit 243be66

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn handle_run_command(
8080
debug_model: bool,
8181
) -> Result<()> {
8282
// Load program settings
83-
let mut settings = Settings::from_path(model_path).context("Failed to load settings.")?;
83+
let mut settings = Settings::load().context("Failed to load settings.")?;
8484

8585
// This setting can be overridden by command-line argument
8686
if debug_model {

src/settings.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,45 @@ impl Settings {
2828
/// # Returns
2929
///
3030
/// The program settings as a `Settings` struct or an error if the file is invalid
31-
pub fn from_path<P: AsRef<Path>>(model_dir: P) -> Result<Settings> {
32-
let file_path = model_dir.as_ref().join(SETTINGS_FILE_NAME);
31+
pub fn load() -> Result<Settings> {
32+
let file_path = Path::new(SETTINGS_FILE_NAME);
3333
if !file_path.is_file() {
3434
return Ok(Settings::default());
3535
}
3636

37-
read_toml(&file_path)
37+
read_toml(file_path)
3838
}
3939
}
4040

4141
#[cfg(test)]
4242
mod tests {
4343
use super::*;
44+
use current_dir::Cwd;
4445
use std::fs::File;
4546
use std::io::Write;
4647
use tempfile::tempdir;
4748

4849
#[test]
4950
fn test_settings_from_path_no_file() {
5051
let dir = tempdir().unwrap();
51-
assert_eq!(
52-
Settings::from_path(dir.path()).unwrap(),
53-
Settings::default()
54-
);
52+
let mut cwd = Cwd::mutex().lock().unwrap();
53+
cwd.set(dir.path()).unwrap();
54+
assert_eq!(Settings::load().unwrap(), Settings::default());
5555
}
5656

5757
#[test]
5858
fn test_settings_from_path() {
5959
let dir = tempdir().unwrap();
60+
let mut cwd = Cwd::mutex().lock().unwrap();
61+
cwd.set(dir.path()).unwrap();
62+
6063
{
61-
let mut file = File::create(dir.path().join(SETTINGS_FILE_NAME)).unwrap();
64+
let mut file = File::create(Path::new(SETTINGS_FILE_NAME)).unwrap();
6265
writeln!(file, "log_level = \"warn\"").unwrap();
6366
}
67+
6468
assert_eq!(
65-
Settings::from_path(dir.path()).unwrap(),
69+
Settings::load().unwrap(),
6670
Settings {
6771
log_level: Some("warn".to_string()),
6872
debug_model: false

0 commit comments

Comments
 (0)