Diff
diff --cc src/bin/main.rs
index d4c74f9,8496fea..cff5555
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@@ -46,24 -36,19 +46,23 @@@ fn main() -> Result<()>
Ok(())
}
-fn load_config() -> Result<oxwm::Config> {
- let config_path = get_config_path().join("config.ron");
-
- if !config_path.exists() {
- println!("No config found at {:?}", config_path);
- println!("Creating default config...");
- init_config()?;
- }
+fn load_config(custom_path: Option<PathBuf>) -> Result<oxwm::Config> {
+ let config_path = if let Some(path) = custom_path {
+ path
+ } else {
+ let default_path = get_config_path().join("config.ron");
+ if !default_path.exists() {
+ println!("No config found at {:?}", default_path);
+ println!("Creating default config...");
+ init_config()?;
+ }
+ default_path
+ };
- let config_str = std::fs::read_to_string(&config_path)
- .map_err(|e| anyhow::anyhow!("Failed to read config file: {}", e))?;
+ let config_str =
+ std::fs::read_to_string(&config_path).with_context(|| "Failed to read config file")?;
- oxwm::config::parse_config(&config_str)
- .map_err(|e| anyhow::anyhow!("Failed to parse config: {}", e))
+ oxwm::config::parse_config(&config_str).with_context(|| "Failed to parse config")
}
fn init_config() -> Result<()> {