diff options
Diffstat (limited to '')
| -rw-r--r-- | src/config.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..f168b27 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,25 @@ +use serde::Deserialize; +use std::fs; +use std::path::Path; + +#[derive(Deserialize)] +pub struct Config { + pub update: Option<String>, + pub build: Option<String>, + pub install: Option<String>, + pub dependencies: Option<Vec<String>>, +} + +impl Config { + pub fn new<P: AsRef<Path>>(filepath: P) -> Option<Self> { + let contents = match fs::read_to_string(filepath) { + Ok(c) => c, + Err(_) => { + eprintln!("no package config found"); + return None; + } + }; + let config: Config = toml::from_str(&contents).expect("failed to parse config"); + Some(config) + } +} |
