]> git.proxmox.com Git - proxmox-backup.git/commitdiff
docs: add utility binary to generate docs
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 10 Feb 2021 09:27:40 +0000 (10:27 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 10 Feb 2021 10:05:02 +0000 (11:05 +0100)
src/bin/docgen.rs [new file with mode: 0644]
src/config/datastore.rs
src/config/remote.rs
src/config/sync.rs
src/config/user.rs

diff --git a/src/bin/docgen.rs b/src/bin/docgen.rs
new file mode 100644 (file)
index 0000000..fa3b35e
--- /dev/null
@@ -0,0 +1,68 @@
+use anyhow::{bail, Error};
+
+use proxmox::api::{
+    format::*,
+    section_config::*,
+};
+
+use proxmox_backup::{
+    config,
+};
+
+fn dump_section_config(config: &SectionConfig) -> String {
+
+    let mut res = String::new();
+
+    let plugin_count = config.plugins().len();
+    
+    for plugin in config.plugins().values() {
+
+        let name = plugin.type_name();
+        let properties = plugin.properties();
+        let skip = match plugin.id_property() {
+            Some(id) => vec![id],
+            None => Vec::new(),
+        };
+
+        if plugin_count > 1 {
+            res.push_str(&format!("\n**Section type** \'``{}``\'\n\n", name));
+        }
+        
+        res.push_str(&dump_api_parameters(properties, "", ParameterDisplayStyle::Config, &skip));
+    }
+    
+    res
+}
+
+fn get_args() -> (String, Vec<String>) {
+
+    let mut args = std::env::args();
+    let prefix = args.next().unwrap();
+    let prefix = prefix.rsplit('/').next().unwrap().to_string(); // without path
+    let args: Vec<String> = args.collect();
+
+    (prefix, args)
+}
+
+fn main() -> Result<(), Error> {
+
+    let (_prefix, args) = get_args();
+
+    if args.len() < 1 {
+        bail!("missing arguments");
+    }
+    
+    for arg in args.iter() {
+        match arg.as_ref() {
+            "datastore.cfg" => println!("{}", dump_section_config(&config::datastore::CONFIG)),
+            "tape.cfg" => println!("{}", dump_section_config(&config::drive::CONFIG)),
+            "user.cfg" => println!("{}", dump_section_config(&config::user::CONFIG)),
+            "remote.cfg" => println!("{}", dump_section_config(&config::remote::CONFIG)),
+            "sync.cfg" => println!("{}", dump_section_config(&config::sync::CONFIG)),
+            "media-pool.cfg" => println!("{}", dump_section_config(&config::media_pool::CONFIG)),
+            _ => bail!("docgen: got unknown type"),
+        }
+    }
+   
+    Ok(())
+}
index e8f552fdfdb47ab81a86cd911dd4b4bc8a30cd36..5105ed6d2c093e5e5089c405d7c9d959c969b25f 100644 (file)
@@ -18,7 +18,7 @@ use proxmox::tools::{fs::replace_file, fs::CreateOptions};
 use crate::api2::types::*;
 
 lazy_static! {
-    static ref CONFIG: SectionConfig = init();
+    pub static ref CONFIG: SectionConfig = init();
 }
 
 // fixme: define better schemas
index 9315575ba1e675390e87ec4465025d9c6c11e460..0ef7067767d0a5ae92f275d0169c91bb46321b0a 100644 (file)
@@ -18,7 +18,7 @@ use proxmox::tools::{fs::replace_file, fs::CreateOptions};
 use crate::api2::types::*;
 
 lazy_static! {
-    static ref CONFIG: SectionConfig = init();
+    pub static ref CONFIG: SectionConfig = init();
 }
 
 pub const REMOTE_PASSWORD_SCHEMA: Schema = StringSchema::new("Password or auth token for remote host.")
index 8febc5d84460a27c89fa9e3cd223d144d81bfb53..5490188ac6fe1e4622d3236a729239f6390ca885 100644 (file)
@@ -18,7 +18,7 @@ use proxmox::tools::{fs::replace_file, fs::CreateOptions};
 use crate::api2::types::*;
 
 lazy_static! {
-    static ref CONFIG: SectionConfig = init();
+    pub static ref CONFIG: SectionConfig = init();
 }
 
 #[api(
index cd9559276978bf6a842a76e857b17efd3ff4308c..ff7e54e4f3bd38c6e61ceb73844af2a867ab9ce5 100644 (file)
@@ -20,7 +20,7 @@ use proxmox::tools::{fs::replace_file, fs::CreateOptions};
 use crate::api2::types::*;
 
 lazy_static! {
-    static ref CONFIG: SectionConfig = init();
+    pub static ref CONFIG: SectionConfig = init();
 }
 
 pub const ENABLE_USER_SCHEMA: Schema = BooleanSchema::new(