Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}

Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions examples/simple_mc/settings.toml

This file was deleted.

2 changes: 1 addition & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 13 additions & 9 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,45 @@ impl Settings {
/// # Returns
///
/// The program settings as a `Settings` struct or an error if the file is invalid
pub fn from_path<P: AsRef<Path>>(model_dir: P) -> Result<Settings> {
let file_path = model_dir.as_ref().join(SETTINGS_FILE_NAME);
pub fn load() -> Result<Settings> {
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;

#[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
Expand Down