diff options
author | jan <jan@ruken.pw> | 2016-09-30 23:16:19 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-09-30 23:16:19 (UTC) |
commit | a6b37fa5e1bd505adfae4888896be2a3aa49ec3a (patch) | |
tree | 0a381e0533489a78758b1516680e274f5fd82216 /src/config.rs | |
parent | 361ea3a80a60bc6595a7a624b6cc5d71ddc8f6fc (diff) |
parsen von traits und tags, wir koennen den configkram eigentlich wieder komplett entfernen. klappt so nicht wirklich.
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs index fc8ee03..f491852 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -15,7 +15,7 @@ pub struct Config { | |||
15 | } | 15 | } |
16 | 16 | ||
17 | impl Config { | 17 | impl Config { |
18 | pub fn from_file(p: &str) -> Self { | 18 | pub fn from_file(p: &str, expected: Vec<&'static str>) -> Self { |
19 | let mut f = File::open(p).unwrap(); | 19 | let mut f = File::open(p).unwrap(); |
20 | let mut buf = String::new(); | 20 | let mut buf = String::new(); |
21 | f.read_to_string(&mut buf).unwrap(); | 21 | f.read_to_string(&mut buf).unwrap(); |
@@ -23,8 +23,6 @@ impl Config { | |||
23 | 23 | ||
24 | let doc = &docs[0]; | 24 | let doc = &docs[0]; |
25 | 25 | ||
26 | println!("{:?}", doc); | ||
27 | |||
28 | let mut sections: HashMap<String, SectionConfig> = HashMap::new(); | 26 | let mut sections: HashMap<String, SectionConfig> = HashMap::new(); |
29 | for (name, entry) in doc["sections"].as_hash().unwrap() { | 27 | for (name, entry) in doc["sections"].as_hash().unwrap() { |
30 | sections.insert(name.as_str().unwrap().into(), | 28 | sections.insert(name.as_str().unwrap().into(), |
@@ -39,6 +37,27 @@ impl Config { | |||
39 | }); | 37 | }); |
40 | } | 38 | } |
41 | 39 | ||
40 | |||
41 | for ex in &expected { | ||
42 | if !sections.contains_key(&ex.to_string()) { | ||
43 | panic!("config: section '{}' not found", ex); | ||
44 | } | ||
45 | } | ||
46 | |||
47 | { | ||
48 | let traits = §ions["traits"]; | ||
49 | if !traits.groups.contains(&"indexed_raw".to_string()) { | ||
50 | panic!("config: no group 'indexed_raw' found in section 'traits'"); | ||
51 | } | ||
52 | if !traits.groups.contains(&"official_raw".to_string()) { | ||
53 | panic!("config: no group 'official_raw' found in section 'traits'"); | ||
54 | } | ||
55 | let tags = §ions["tags"]; | ||
56 | if !tags.groups.contains(&"tags_raw".to_string()) { | ||
57 | panic!("config: no group 'tags_raw' found in section 'tags'"); | ||
58 | } | ||
59 | } | ||
60 | |||
42 | Config { sections: sections } | 61 | Config { sections: sections } |
43 | } | 62 | } |
44 | } | 63 | } |