diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..9ba4a7f --- /dev/null +++ b/src/config.rs @@ -0,0 +1,33 @@ +use log::debug; +use serde::Deserialize; +use std::default::Default; +use std::fs; +use std::path::{Path, PathBuf}; + +#[derive(Default, Debug, Deserialize)] +pub struct Configuration { + pub default_base_image: Option<PathBuf>, +} + +#[derive(Debug, thiserror::Error)] +pub enum ConfigurationError { + #[error(transparent)] + IoError(#[from] std::io::Error), + + #[error(transparent)] + YamlError(#[from] serde_yaml::Error), +} + +impl Configuration { + pub fn from_file(filename: &Path) -> Result<Self, ConfigurationError> { + if filename.exists() { + debug!("reading configuration file {}", filename.display()); + let config = fs::read(filename)?; + let config: Configuration = serde_yaml::from_slice(&config)?; + debug!("config: {:#?}", config); + Ok(config) + } else { + Ok(Self::default()) + } + } +} |