Skip to content

Commit 52f3b3a

Browse files
committed
fix(config): Simplify blueprint configuration loading
- Remove environment variable handling for blueprint path. - Directly include the blueprint content from `whid.toml` using `include_str!`. - Update configuration source to use the included string for improved clarity and performance.
1 parent e569256 commit 52f3b3a

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

src/config.rs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ pub struct Settings {
1616

1717
impl Settings {
1818
pub fn new() -> Result<Self, ConfigError> {
19-
let blueprint_path = match std::env::var("CARGO_MANIFEST_DIR") {
20-
Ok(manifest_dir) => {
21-
let mut path = PathBuf::from(manifest_dir);
22-
path.push("whid.toml");
23-
path
24-
}
25-
Err(_) => {
26-
// Fallback for release builds or when not using Cargo.
27-
// Assumes whid.toml is in the current working directory.
28-
PathBuf::from("whid.toml")
29-
}
30-
};
31-
3219
let user_config_path = get_user_config_path();
3320

3421
// Ensure the user config directory exists
@@ -39,8 +26,7 @@ impl Settings {
3926
}
4027

4128
// Read the blueprint
42-
let blueprint_content = fs::read_to_string(&blueprint_path)
43-
.expect("Could not read blueprint config file");
29+
let blueprint_content = include_str!("../whid.toml");
4430
let blueprint_table: toml::Table = blueprint_content.parse()
4531
.expect("Could not parse blueprint config as TOML");
4632

@@ -68,7 +54,7 @@ impl Settings {
6854
let s = Config::builder()
6955
// 1. Load project defaults from whid.toml (blueprint). Required.
7056
// This still acts as the base for deserialization structure.
71-
.add_source(File::from(blueprint_path).required(true))
57+
.add_source(config::File::from_str(blueprint_content, config::FileFormat::Toml))
7258
// 2. Merge user's global config.
7359
.add_source(File::from(user_config_path).required(true))
7460
// 3. Merge local whid.toml from CWD. Optional override.

0 commit comments

Comments
 (0)