diff options
author | jan <jan@ruken.pw> | 2016-10-01 10:45:55 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-10-01 10:45:55 (UTC) |
commit | ad63b49b94bf4b4596e6420e37d265a57b77d731 (patch) | |
tree | 73234b1a5f4d34e6b1771e4309374fd05bebd881 /src/config.rs | |
parent | a6b37fa5e1bd505adfae4888896be2a3aa49ec3a (diff) |
config entfernt, extra details parsen
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/src/config.rs b/src/config.rs deleted file mode 100644 index f491852..0000000 --- a/src/config.rs +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
1 | extern crate yaml_rust; | ||
2 | use self::yaml_rust::YamlLoader; | ||
3 | |||
4 | use std::collections::HashMap; | ||
5 | use std::fs::File; | ||
6 | use std::io::prelude::*; | ||
7 | |||
8 | pub struct SectionConfig { | ||
9 | pub pattern: String, | ||
10 | pub groups: Vec<String>, | ||
11 | } | ||
12 | |||
13 | pub struct Config { | ||
14 | pub sections: HashMap<String, SectionConfig>, | ||
15 | } | ||
16 | |||
17 | impl Config { | ||
18 | pub fn from_file(p: &str, expected: Vec<&'static str>) -> Self { | ||
19 | let mut f = File::open(p).unwrap(); | ||
20 | let mut buf = String::new(); | ||
21 | f.read_to_string(&mut buf).unwrap(); | ||
22 | let docs = YamlLoader::load_from_str(&buf).unwrap(); | ||
23 | |||
24 | let doc = &docs[0]; | ||
25 | |||
26 | let mut sections: HashMap<String, SectionConfig> = HashMap::new(); | ||
27 | for (name, entry) in doc["sections"].as_hash().unwrap() { | ||
28 | sections.insert(name.as_str().unwrap().into(), | ||
29 | SectionConfig { | ||
30 | pattern: entry["pattern"].as_str().unwrap().into(), | ||
31 | groups: entry["groups"] | ||
32 | .as_vec() | ||
33 | .unwrap() | ||
34 | .into_iter() | ||
35 | .map(|v| v.as_str().unwrap().into()) | ||
36 | .collect(), | ||
37 | }); | ||
38 | } | ||
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 | |||
61 | Config { sections: sections } | ||
62 | } | ||
63 | } | ||