]> git.proxmox.com Git - proxmox-backup.git/commitdiff
SectionConfig::parse - return Value
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 27 Nov 2018 11:54:40 +0000 (12:54 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 27 Nov 2018 11:54:40 +0000 (12:54 +0100)
src/section_config.rs

index 826117b8d94ac2386a5ab85537b899437dcf0117..d89415da5e0f1ef31172196b1a1e974bdb177f23 100644 (file)
@@ -25,8 +25,8 @@ pub struct SectionConfig {
     plugins: HashMap<String, SectionConfigPlugin>,
 
     id_schema: Arc<Schema>,
-    parse_section_header: fn(&str) ->  Option<(String, String)>,
-    parse_section_content: fn(&str) ->  Option<(String, String)>,
+    parse_section_header: fn(&str) -> Option<(String, String)>,
+    parse_section_content: fn(&str) -> Option<(String, String)>,
 }
 
 enum ParseState<'a> {
@@ -49,7 +49,7 @@ impl SectionConfig {
         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;
 
@@ -64,6 +64,15 @@ impl SectionConfig {
             Ok(())
         };
 
+        let mut result = json!({
+            "ids": {},
+            "order": {}
+        });
+
+        let mut create_section = |section_id, config| {
+            result[section_id] = config;
+        };
+
         for line in raw.lines() {
             line_no += 1;
 
@@ -98,6 +107,7 @@ impl SectionConfig {
                         if let Err(err) = test_required_properties(config, &plugin.properties) {
                             bail!("file '{}' line {} - {}", filename, line_no, err.to_string());
                         }
+                        create_section(section_id.clone(), config.clone());
                         state = ParseState::BeforeHeader;
                         continue;
                     }
@@ -135,9 +145,10 @@ impl SectionConfig {
             if let Err(err) = test_required_properties(config, &plugin.properties) {
                 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)> {