fix: make `config.experimental` optional (#339)
* fix: make config.experimental` optional * add unit test for empty toml configrelease-0.0
parent
9e44d469d1
commit
220fcc0d65
|
|
@ -10,22 +10,30 @@ use crate::path::{config_file, repositories_dir};
|
|||
|
||||
#[derive(Deserialize, Default)]
|
||||
pub struct Config {
|
||||
#[serde(default)]
|
||||
pub repositories: Vec<Repository>,
|
||||
|
||||
#[serde(default)]
|
||||
pub experimental: Experimental,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
pub struct Experimental {
|
||||
#[serde(default = "default_as_false")]
|
||||
pub enable_prompt_rewrite: bool,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn load() -> Result<Self, Error> {
|
||||
let file = serdeconv::from_toml_file(crate::path::config_file().as_path());
|
||||
file.map_err(|_| {
|
||||
file.map_err(|err| {
|
||||
Error::new(
|
||||
ErrorKind::InvalidData,
|
||||
format!("Config {:?} doesn't exist or is not valid", config_file()),
|
||||
format!(
|
||||
"Config {:?} doesn't exist or is not valid: `{:?}`",
|
||||
config_file(),
|
||||
err
|
||||
),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
@ -41,3 +49,18 @@ impl Repository {
|
|||
repositories_dir().join(filenamify(&self.git_url))
|
||||
}
|
||||
}
|
||||
|
||||
fn default_as_false() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Config;
|
||||
|
||||
#[test]
|
||||
fn it_parses_empty_config() {
|
||||
let config = serdeconv::from_toml_str::<Config>("");
|
||||
debug_assert!(config.is_ok(), "{}", config.err().unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue