summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-25 12:29:44 +0200
committerLars Wirzenius <liw@liw.fi>2021-03-25 13:16:13 +0200
commit00dc4a7a85b32c4337dd3672adec2cbfe3597bfe (patch)
tree20df497a743e8442f9725c2f5ab552747363a9d1 /src/config.rs
parent7d906d7f5436705ec3f2f3f5c4d8629c79f98fde (diff)
downloadvmadm-00dc4a7a85b32c4337dd3672adec2cbfe3597bfe.tar.gz
feat: allow ~/ in config, specification files
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/config.rs b/src/config.rs
index 1866971..3f1b341 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,5 +1,6 @@
//! Tool configuration.
+use crate::util::{expand_optional_pathbuf, expand_optional_pathbufs};
use log::debug;
use serde::Deserialize;
use std::default::Default;
@@ -57,11 +58,20 @@ impl Configuration {
debug!("reading configuration file {}", filename.display());
let config = fs::read(filename)
.map_err(|err| ConfigurationError::ReadError(filename.to_path_buf(), err))?;
- let config: Configuration = serde_yaml::from_slice(&config)?;
+ let mut config: Configuration = serde_yaml::from_slice(&config)?;
+ config.expand_tildes();
debug!("config: {:#?}", config);
Ok(config)
} else {
Ok(Self::default())
}
}
+
+ fn expand_tildes(&mut self) {
+ expand_optional_pathbuf(&mut self.default_base_image);
+ expand_optional_pathbuf(&mut self.image_directory);
+ expand_optional_pathbuf(&mut self.image_directory);
+ expand_optional_pathbuf(&mut self.ca_key);
+ expand_optional_pathbufs(&mut self.authorized_keys)
+ }
}