summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-03-01 10:13:15 +0200
committerLars Wirzenius <liw@liw.fi>2021-03-01 12:28:31 +0200
commita4e59f7f6363c2bc62b91298f41b5b645842385e (patch)
tree46659f0fa296fe2128d1a7bcb929008d034f51c1 /src/config.rs
parent05dbbc46d7b3fad9e7a1b85e10469022e07e0b40 (diff)
downloadvmadm-a4e59f7f6363c2bc62b91298f41b5b645842385e.tar.gz
feat: change how command line interface works
Easier to use now. --config before subcommand was annoying.
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs33
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())
+ }
+ }
+}