Fix config default location
The default location is now correctly used again
This commit is contained in:
parent
91c109a902
commit
b30400ac47
1 changed files with 14 additions and 12 deletions
|
|
@ -60,28 +60,30 @@ impl Config {
|
||||||
.map_err(|e| ConfigError::IoPath(e, path.to_path_buf()))?;
|
.map_err(|e| ConfigError::IoPath(e, path.to_path_buf()))?;
|
||||||
Ok(Config::from_yaml(&yaml_config)?)
|
Ok(Config::from_yaml(&yaml_config)?)
|
||||||
}
|
}
|
||||||
Err(_) => Ok(Config::default()),
|
Err(e) => Err(ConfigError::IoPath(e, path.into())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Deserializes the config from an optional path, or a platform specific path,
|
/// Deserializes the config from a default platform specific path,
|
||||||
/// merges the default configuration - options take precedence.
|
/// merges the default configuration - options take precedence.
|
||||||
fn from_option_or_default(option: Option<PathBuf>) -> ConfigResult {
|
fn from_default_path() -> ConfigResult {
|
||||||
if let Some(config_path) = option {
|
let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
|
||||||
Ok(Config::new(&config_path)?)
|
let mut config_path: PathBuf = project_dirs.config_dir().to_owned();
|
||||||
} else {
|
config_path.push("config.yaml");
|
||||||
let project_dirs = ProjectDirs::from("org", "Zellij Contributors", "Zellij").unwrap();
|
|
||||||
let mut config_path: PathBuf = project_dirs.config_dir().to_owned();
|
match Config::new(&config_path) {
|
||||||
config_path.push("config.yaml");
|
Ok(config) => Ok(config),
|
||||||
Ok(Config::new(&config_path)?)
|
Err(ConfigError::IoPath(_,_)) => Ok(Config::default()),
|
||||||
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Entry point of the configuration
|
||||||
pub fn from_cli_config(cli_config: Option<ConfigCli>) -> ConfigResult {
|
pub fn from_cli_config(cli_config: Option<ConfigCli>) -> ConfigResult {
|
||||||
match cli_config {
|
match cli_config {
|
||||||
Some(ConfigCli::Config { clean, .. }) if clean => Ok(Config::default()),
|
Some(ConfigCli::Config { clean, .. }) if clean => Ok(Config::default()),
|
||||||
Some(ConfigCli::Config { path, .. }) => Ok(Config::from_option_or_default(path)?),
|
Some(ConfigCli::Config { path, .. }) if path.is_some()=> Ok(Config::new(&path.unwrap())?),
|
||||||
None => Ok(Config::default()),
|
Some(_) | None => Ok(Config::from_default_path()?),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue