]> git.proxmox.com Git - proxmox-backup.git/blob - src/bin/docgen.rs
docs: add utility binary to generate docs
[proxmox-backup.git] / src / bin / docgen.rs
1 use anyhow::{bail, Error};
2
3 use proxmox::api::{
4 format::*,
5 section_config::*,
6 };
7
8 use proxmox_backup::{
9 config,
10 };
11
12 fn dump_section_config(config: &SectionConfig) -> String {
13
14 let mut res = String::new();
15
16 let plugin_count = config.plugins().len();
17
18 for plugin in config.plugins().values() {
19
20 let name = plugin.type_name();
21 let properties = plugin.properties();
22 let skip = match plugin.id_property() {
23 Some(id) => vec![id],
24 None => Vec::new(),
25 };
26
27 if plugin_count > 1 {
28 res.push_str(&format!("\n**Section type** \'``{}``\'\n\n", name));
29 }
30
31 res.push_str(&dump_api_parameters(properties, "", ParameterDisplayStyle::Config, &skip));
32 }
33
34 res
35 }
36
37 fn get_args() -> (String, Vec<String>) {
38
39 let mut args = std::env::args();
40 let prefix = args.next().unwrap();
41 let prefix = prefix.rsplit('/').next().unwrap().to_string(); // without path
42 let args: Vec<String> = args.collect();
43
44 (prefix, args)
45 }
46
47 fn main() -> Result<(), Error> {
48
49 let (_prefix, args) = get_args();
50
51 if args.len() < 1 {
52 bail!("missing arguments");
53 }
54
55 for arg in args.iter() {
56 match arg.as_ref() {
57 "datastore.cfg" => println!("{}", dump_section_config(&config::datastore::CONFIG)),
58 "tape.cfg" => println!("{}", dump_section_config(&config::drive::CONFIG)),
59 "user.cfg" => println!("{}", dump_section_config(&config::user::CONFIG)),
60 "remote.cfg" => println!("{}", dump_section_config(&config::remote::CONFIG)),
61 "sync.cfg" => println!("{}", dump_section_config(&config::sync::CONFIG)),
62 "media-pool.cfg" => println!("{}", dump_section_config(&config::media_pool::CONFIG)),
63 _ => bail!("docgen: got unknown type"),
64 }
65 }
66
67 Ok(())
68 }