[pbs-devel] [RFC proxmox 2/2] schema: add extra info to array parameters

Fabian Grünbichler f.gruenbichler at proxmox.com
Wed Sep 15 15:36:34 CEST 2021


it's not immediately obvious that they can be specified more than once
otherwise.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
see previous patch for some remaining warts that are not yet solved..

 proxmox/src/api/format.rs | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/proxmox/src/api/format.rs b/proxmox/src/api/format.rs
index a362b21..64fcd0a 100644
--- a/proxmox/src/api/format.rs
+++ b/proxmox/src/api/format.rs
@@ -134,15 +134,15 @@ pub fn get_property_description(
 ) -> String {
     let type_text = get_schema_type_text(schema, style);
 
-    let (descr, default) = match schema {
-        Schema::Null => ("null", None),
-        Schema::String(ref schema) => (schema.description, schema.default.map(|v| v.to_owned())),
-        Schema::Boolean(ref schema) => (schema.description, schema.default.map(|v| v.to_string())),
-        Schema::Integer(ref schema) => (schema.description, schema.default.map(|v| v.to_string())),
-        Schema::Number(ref schema) => (schema.description, schema.default.map(|v| v.to_string())),
-        Schema::Object(ref schema) => (schema.description, None),
-        Schema::AllOf(ref schema) => (schema.description, None),
-        Schema::Array(ref schema) => (schema.description, None),
+    let (descr, default, extra) = match schema {
+        Schema::Null => ("null", None, None),
+        Schema::String(ref schema) => (schema.description, schema.default.map(|v| v.to_owned()), None),
+        Schema::Boolean(ref schema) => (schema.description, schema.default.map(|v| v.to_string()), None),
+        Schema::Integer(ref schema) => (schema.description, schema.default.map(|v| v.to_string()), None),
+        Schema::Number(ref schema) => (schema.description, schema.default.map(|v| v.to_string()), None),
+        Schema::Object(ref schema) => (schema.description, None, None),
+        Schema::AllOf(ref schema) => (schema.description, None, None),
+        Schema::Array(ref schema) => (schema.description, None, Some(String::from("Can be specified more than once."))),
     };
 
     let default_text = match default {
@@ -150,6 +150,11 @@ pub fn get_property_description(
         None => String::new(),
     };
 
+    let descr = match extra {
+        Some(extra) => format!("{} {}", descr, extra),
+        None => String::from(descr),
+    };
+
     if format == DocumentationFormat::ReST {
         let mut text = match style {
             ParameterDisplayStyle::Config => {
@@ -169,7 +174,7 @@ pub fn get_property_description(
             }
         };
 
-        text.push_str(&wrap_text("", "  ", descr, 80));
+        text.push_str(&wrap_text("", "  ", &descr, 80));
         text.push('\n');
 
         text
@@ -184,7 +189,7 @@ pub fn get_property_description(
         let mut text = format!(" {:-10} {}{}", display_name, type_text, default_text);
         let indent = "             ";
         text.push('\n');
-        text.push_str(&wrap_text(indent, indent, descr, 80));
+        text.push_str(&wrap_text(indent, indent, &descr, 80));
 
         text
     }
-- 
2.30.2






More information about the pbs-devel mailing list