diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-11-10 08:18:19 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-11-10 08:26:33 +0100 |
commit | 9d72601e57eeb821314b6188e60817137baf223d (patch) | |
tree | 41b1420d61860b4c4bf5946e557e7a25bfa54ab6 /src/config/configuration.rs | |
parent | 451b417f547c9c58a66847bf472e82664c87460b (diff) |
Split configuration module in multiple files
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/config/configuration.rs')
-rw-r--r-- | src/config/configuration.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/config/configuration.rs b/src/config/configuration.rs new file mode 100644 index 0000000..294c5cb --- /dev/null +++ b/src/config/configuration.rs @@ -0,0 +1,40 @@ +use std::collections::BTreeMap; +use std::ops::Deref; +use std::path::PathBuf; + +use anyhow::Context; +use anyhow::Result; +use handlebars::Handlebars; + +use crate::config::NotValidatedConfiguration; + +#[derive(Debug)] +pub struct Configuration<'reg> { + pub (in crate::config) inner: NotValidatedConfiguration, + pub (in crate::config) hb: Handlebars<'reg>, +} + +impl<'reg> Deref for Configuration<'reg> { + type Target = NotValidatedConfiguration; + + fn deref(&self) -> &Self::Target { + &self.inner + } +} + +impl<'reg> Configuration<'reg> { + /// Get the path to the releases directory, interpolate every variable used in the config + pub fn releases_directory(&self, hm: &BTreeMap<String, String>) -> Result<PathBuf> { + self.hb.render("releases", hm) + .map(PathBuf::from) + .context("Interpolating variables into 'release' setting from configuration") + } + + /// Get the path to the staging directory, interpolate every variable used in the config + pub fn staging_directory(&self, hm: &BTreeMap<String, String>) -> Result<PathBuf> { + self.hb.render("staging", hm) + .map(PathBuf::from) + .context("Interpolating variables into 'staging' setting from configuration") + } +} + |