diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f3f86c2ed..af39314d3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,6 +48,7 @@ jobs: mkdir muse2 cp target/release/muse2${{ matrix.exe_suffix }} muse2 cp LICENSE muse2/LICENCE.txt + cp assets/settings.toml muse2 cp assets/readme/readme_${{ matrix.osname }}.txt muse2/README.txt - uses: actions/upload-artifact@v4 if: ${{ github.event_name != 'release' }} diff --git a/Cargo.lock b/Cargo.lock index 1698d085c..eaa0fe2be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -324,6 +324,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "current_dir" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eef2919c1b81568a02425279ba21d61a450e76848eb1b50dff756b739529b70a" + [[package]] name = "deranged" version = "0.4.0" @@ -804,6 +810,7 @@ dependencies = [ "clap", "clap-markdown", "csv", + "current_dir", "derive_more", "fern", "float-cmp", diff --git a/Cargo.toml b/Cargo.toml index d458db9ee..940abf6e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ platform-info = "2.0.5" derive_more = "0.99" [dev-dependencies] +current_dir = "0.1.2" regex = "1.11.1" rstest = {version = "0.25.0", default-features = false, features = ["crate-name"]} diff --git a/examples/simple/settings.toml b/assets/settings.toml similarity index 100% rename from examples/simple/settings.toml rename to assets/settings.toml diff --git a/examples/simple_mc/settings.toml b/examples/simple_mc/settings.toml deleted file mode 100644 index 35f983615..000000000 --- a/examples/simple_mc/settings.toml +++ /dev/null @@ -1,3 +0,0 @@ -# Modify this file if you want to change your program settings -# log_level = "info" -# debug_model = false diff --git a/src/commands.rs b/src/commands.rs index a9f1f723f..7d563a42e 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -80,7 +80,7 @@ pub fn handle_run_command( debug_model: bool, ) -> Result<()> { // Load program settings - let mut settings = Settings::from_path(model_path).context("Failed to load settings.")?; + let mut settings = Settings::load().context("Failed to load settings.")?; // This setting can be overridden by command-line argument if debug_model { diff --git a/src/settings.rs b/src/settings.rs index 1acb18d5e..8fdc80b5a 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -28,19 +28,20 @@ impl Settings { /// # Returns /// /// The program settings as a `Settings` struct or an error if the file is invalid - pub fn from_path>(model_dir: P) -> Result { - let file_path = model_dir.as_ref().join(SETTINGS_FILE_NAME); + pub fn load() -> Result { + let file_path = Path::new(SETTINGS_FILE_NAME); if !file_path.is_file() { return Ok(Settings::default()); } - read_toml(&file_path) + read_toml(file_path) } } #[cfg(test)] mod tests { use super::*; + use current_dir::Cwd; use std::fs::File; use std::io::Write; use tempfile::tempdir; @@ -48,21 +49,24 @@ mod tests { #[test] fn test_settings_from_path_no_file() { let dir = tempdir().unwrap(); - assert_eq!( - Settings::from_path(dir.path()).unwrap(), - Settings::default() - ); + let mut cwd = Cwd::mutex().lock().unwrap(); + cwd.set(dir.path()).unwrap(); + assert_eq!(Settings::load().unwrap(), Settings::default()); } #[test] fn test_settings_from_path() { let dir = tempdir().unwrap(); + let mut cwd = Cwd::mutex().lock().unwrap(); + cwd.set(dir.path()).unwrap(); + { - let mut file = File::create(dir.path().join(SETTINGS_FILE_NAME)).unwrap(); + let mut file = File::create(Path::new(SETTINGS_FILE_NAME)).unwrap(); writeln!(file, "log_level = \"warn\"").unwrap(); } + assert_eq!( - Settings::from_path(dir.path()).unwrap(), + Settings::load().unwrap(), Settings { log_level: Some("warn".to_string()), debug_model: false