SectionConfig::parse - return Value
This commit is contained in:
parent
826698d56f
commit
ee7fc4335a
|
@ -49,7 +49,7 @@ impl SectionConfig {
|
||||||
self.plugins.insert(plugin.type_name.clone(), plugin);
|
self.plugins.insert(plugin.type_name.clone(), plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse(&self, filename: &str, raw: &str) -> Result<(), Error> {
|
pub fn parse(&self, filename: &str, raw: &str) -> Result<Value, Error> {
|
||||||
|
|
||||||
let mut line_no = 0;
|
let mut line_no = 0;
|
||||||
|
|
||||||
|
@ -64,6 +64,15 @@ impl SectionConfig {
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mut result = json!({
|
||||||
|
"ids": {},
|
||||||
|
"order": {}
|
||||||
|
});
|
||||||
|
|
||||||
|
let mut create_section = |section_id, config| {
|
||||||
|
result[section_id] = config;
|
||||||
|
};
|
||||||
|
|
||||||
for line in raw.lines() {
|
for line in raw.lines() {
|
||||||
line_no += 1;
|
line_no += 1;
|
||||||
|
|
||||||
|
@ -98,6 +107,7 @@ impl SectionConfig {
|
||||||
if let Err(err) = test_required_properties(config, &plugin.properties) {
|
if let Err(err) = test_required_properties(config, &plugin.properties) {
|
||||||
bail!("file '{}' line {} - {}", filename, line_no, err.to_string());
|
bail!("file '{}' line {} - {}", filename, line_no, err.to_string());
|
||||||
}
|
}
|
||||||
|
create_section(section_id.clone(), config.clone());
|
||||||
state = ParseState::BeforeHeader;
|
state = ParseState::BeforeHeader;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -135,9 +145,10 @@ impl SectionConfig {
|
||||||
if let Err(err) = test_required_properties(config, &plugin.properties) {
|
if let Err(err) = test_required_properties(config, &plugin.properties) {
|
||||||
bail!("file '{}' line {} - {}", filename, line_no, err.to_string());
|
bail!("file '{}' line {} - {}", filename, line_no, err.to_string());
|
||||||
}
|
}
|
||||||
|
create_section(section_id.clone(), config.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn default_parse_section_content(line: &str) -> Option<(String, String)> {
|
pub fn default_parse_section_content(line: &str) -> Option<(String, String)> {
|
||||||
|
|
Loading…
Reference in New Issue