From 2322a980d042bafd8072fbd6f1efc4964fe1f50d Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 10 Feb 2021 10:27:40 +0100 Subject: [PATCH] docs: add utility binary to generate docs --- src/bin/docgen.rs | 68 +++++++++++++++++++++++++++++++++++++++++ src/config/datastore.rs | 2 +- src/config/remote.rs | 2 +- src/config/sync.rs | 2 +- src/config/user.rs | 2 +- 5 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 src/bin/docgen.rs diff --git a/src/bin/docgen.rs b/src/bin/docgen.rs new file mode 100644 index 00000000..fa3b35ee --- /dev/null +++ b/src/bin/docgen.rs @@ -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) { + + let mut args = std::env::args(); + let prefix = args.next().unwrap(); + let prefix = prefix.rsplit('/').next().unwrap().to_string(); // without path + let args: Vec = 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(()) +} diff --git a/src/config/datastore.rs b/src/config/datastore.rs index e8f552fd..5105ed6d 100644 --- a/src/config/datastore.rs +++ b/src/config/datastore.rs @@ -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 diff --git a/src/config/remote.rs b/src/config/remote.rs index 9315575b..0ef70677 100644 --- a/src/config/remote.rs +++ b/src/config/remote.rs @@ -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.") diff --git a/src/config/sync.rs b/src/config/sync.rs index 8febc5d8..5490188a 100644 --- a/src/config/sync.rs +++ b/src/config/sync.rs @@ -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( diff --git a/src/config/user.rs b/src/config/user.rs index cd955927..ff7e54e4 100644 --- a/src/config/user.rs +++ b/src/config/user.rs @@ -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(