diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-11-22 18:43:24 +0200 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-11-22 18:43:24 +0200 |
commit | 3d3ead02e9fdbfbedde1d476f1e2bc4058a3afe1 (patch) | |
tree | 7b35562043a232d942786f0aa978a4965f6ac591 /ui/src/conf.rs | |
parent | 1063bb73b5a996b947a56789b5b270d5e38efeea (diff) |
bin: add --test-config flag
meli --test-config PATH tests a configuration file for syntax issues or missing options.
Caveat: right now undefined options/values do not return an error.
Backend specific options are also not validated.
Diffstat (limited to 'ui/src/conf.rs')
-rw-r--r-- | ui/src/conf.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/ui/src/conf.rs b/ui/src/conf.rs index 184c706e..feed7906 100644 --- a/ui/src/conf.rs +++ b/ui/src/conf.rs @@ -231,7 +231,7 @@ impl FileAccount { } #[derive(Debug, Clone, Default, Serialize, Deserialize)] -struct FileSettings { +pub struct FileSettings { accounts: HashMap<String, FileAccount>, #[serde(default)] pager: PagerSettings, @@ -342,6 +342,21 @@ impl FileSettings { Ok(s.unwrap()) } + + pub fn validate(path: &str) -> Result<()> { + let mut file = File::open(path)?; + let mut contents = String::new(); + file.read_to_string(&mut contents)?; + let s: std::result::Result<FileSettings, toml::de::Error> = toml::from_str(&contents); + if let Err(e) = s { + return Err(MeliError::new(format!( + "Config file contains errors: {}", + e.to_string() + ))); + } + + Ok(()) + } } impl Settings { |