Skip to content

Commit

Permalink
🔧 fix: fix the issue of not finding the configuration file. (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liquidwe authored Dec 8, 2024
1 parent fe49203 commit 89faf24
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions gui/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ lazy_static! {
impl Settings {
pub fn new() -> Result<Self, ConfigError> {
let mut builder = Config::builder();

let default_config = include_str!("../config/default.yaml");
builder = builder
.add_source(config::File::from_str(
default_config,
config::FileFormat::Yaml
));

let exe_path = std::env::current_exe()
.unwrap_or_else(|_| std::path::PathBuf::from("."));
Expand All @@ -52,27 +59,16 @@ impl Settings {
"../config/default.yaml".to_string(),
"../../config/default.yaml".to_string(),
format!("{}/config/default.yaml", exe_dir.display()),
format!("{}/config/default.yaml",
std::env::var("OUT_DIR").unwrap_or_else(|_| String::from("target/debug"))),
];

let mut config_loaded = false;
for location in config_locations {
let path = Path::new(&location);
if path.exists() {
let file = File::with_name(&location).format(FileFormat::Yaml);
builder = builder.add_source(file);
config_loaded = true;
builder = builder.add_source(File::with_name(&location).format(FileFormat::Yaml));
break;
} else {
println!("Configuration file not found: {}", location);
}
}

if !config_loaded {
return Err(ConfigError::NotFound("Could not find config file".into()));
}

builder.build()?.try_deserialize()
}

Expand Down

0 comments on commit 89faf24

Please sign in to comment.